Я решил проблему, ответ @FreakyAli также помог в получении решения
Создать службу:
[Service(Name = "com.companyname.app.RebootService")]
public class RebootService : Service
{
public override void OnCreate()
{
base.OnCreate();
}
public override IBinder OnBind(Intent intent)
{
return null;
}
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
Toast.MakeText(this, "Service STARTED!", ToastLength.Long).Show();
return StartCommandResult.Sticky;
}
public override void OnDestroy()
{
base.OnDestroy();
Toast.MakeText(this, "Service STOPED", ToastLength.Long).Show();
}
}
}
Создать BroadcastReciver:
[BroadcastReceiver(Enabled =true, Name ="com.companyname.Sortex.RebootReceiver")]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class RebootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
}
}
регистрация службы и BroadcastReceiver на AndroidManifest. xml
<service android:name="com.companyname.app.RebootService"/>
<receiver android:name="com.companyname.app.RebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Вызов службы по методу OnReceive приемника Broadcast:
Intent serviceIntent = new Intent(context, typeof(RebootService));
context.StartService(serviceIntent);