Xamarin.Android - Start service on Boot Completed












0















I am trying to start a service when my device boots up, but the service never starts.



I have added:



<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


to AndroidManifest.xml. My BroadcastReceiver looks like this:



[BroadcastReceiver]
[IntentFilter(new { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
var start = new Intent(context, typeof(AlertSyncService));
start.AddFlags(ActivityFlags.NewTask);
context.StartService(start);
}
}


I have confirmed my service is not the issue (tested by starting the same service on button click - it works fine). The issue is definitely that the BroadcastReceiver is never receiving the event. I've also ensured that I open the app once before rebooting - I saw in a similar question that this is necessary, as apps are installed in a "stopped state".



Does anybody have any ideas what could be causing this not to work? I'm relatively new to this, so highly likely I've missed something obvious!



Thanks










share|improve this question























  • Top of my head without see the logcat output : [BroadcastReceiver(Enabled = true)] Review the testing (via adb) section of this answer: stackoverflow.com/a/47601952/4984832

    – SushiHangover
    Nov 28 '18 at 22:32













  • @SushiHangover I've done the adb testing, and think this is the issue: java.lang.RuntimeException: Unable to start receiver md527b6cae80f13bfed8573ffa181fefc60.BootReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=MyApp.MyApp/md527b6cae80f13bfed8573ffa181fefc60.AlertSyncService }: app is in background uid UidRecord{6ef4e91 u0a6 ... However, I don't know how to resolve this! Any ideas? I have tried running it with ContextCompat.StartForegroundService(...) But this has the same issue.

    – A.Davis
    Nov 29 '18 at 18:41













  • stackoverflow.com/questions/46445265/…

    – SushiHangover
    Nov 29 '18 at 20:23
















0















I am trying to start a service when my device boots up, but the service never starts.



I have added:



<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


to AndroidManifest.xml. My BroadcastReceiver looks like this:



[BroadcastReceiver]
[IntentFilter(new { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
var start = new Intent(context, typeof(AlertSyncService));
start.AddFlags(ActivityFlags.NewTask);
context.StartService(start);
}
}


I have confirmed my service is not the issue (tested by starting the same service on button click - it works fine). The issue is definitely that the BroadcastReceiver is never receiving the event. I've also ensured that I open the app once before rebooting - I saw in a similar question that this is necessary, as apps are installed in a "stopped state".



Does anybody have any ideas what could be causing this not to work? I'm relatively new to this, so highly likely I've missed something obvious!



Thanks










share|improve this question























  • Top of my head without see the logcat output : [BroadcastReceiver(Enabled = true)] Review the testing (via adb) section of this answer: stackoverflow.com/a/47601952/4984832

    – SushiHangover
    Nov 28 '18 at 22:32













  • @SushiHangover I've done the adb testing, and think this is the issue: java.lang.RuntimeException: Unable to start receiver md527b6cae80f13bfed8573ffa181fefc60.BootReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=MyApp.MyApp/md527b6cae80f13bfed8573ffa181fefc60.AlertSyncService }: app is in background uid UidRecord{6ef4e91 u0a6 ... However, I don't know how to resolve this! Any ideas? I have tried running it with ContextCompat.StartForegroundService(...) But this has the same issue.

    – A.Davis
    Nov 29 '18 at 18:41













  • stackoverflow.com/questions/46445265/…

    – SushiHangover
    Nov 29 '18 at 20:23














0












0








0








I am trying to start a service when my device boots up, but the service never starts.



I have added:



<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


to AndroidManifest.xml. My BroadcastReceiver looks like this:



[BroadcastReceiver]
[IntentFilter(new { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
var start = new Intent(context, typeof(AlertSyncService));
start.AddFlags(ActivityFlags.NewTask);
context.StartService(start);
}
}


I have confirmed my service is not the issue (tested by starting the same service on button click - it works fine). The issue is definitely that the BroadcastReceiver is never receiving the event. I've also ensured that I open the app once before rebooting - I saw in a similar question that this is necessary, as apps are installed in a "stopped state".



Does anybody have any ideas what could be causing this not to work? I'm relatively new to this, so highly likely I've missed something obvious!



Thanks










share|improve this question














I am trying to start a service when my device boots up, but the service never starts.



I have added:



<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


to AndroidManifest.xml. My BroadcastReceiver looks like this:



[BroadcastReceiver]
[IntentFilter(new { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
var start = new Intent(context, typeof(AlertSyncService));
start.AddFlags(ActivityFlags.NewTask);
context.StartService(start);
}
}


I have confirmed my service is not the issue (tested by starting the same service on button click - it works fine). The issue is definitely that the BroadcastReceiver is never receiving the event. I've also ensured that I open the app once before rebooting - I saw in a similar question that this is necessary, as apps are installed in a "stopped state".



Does anybody have any ideas what could be causing this not to work? I'm relatively new to this, so highly likely I've missed something obvious!



Thanks







c# android xamarin android-intent broadcastreceiver






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '18 at 22:21









A.DavisA.Davis

11




11













  • Top of my head without see the logcat output : [BroadcastReceiver(Enabled = true)] Review the testing (via adb) section of this answer: stackoverflow.com/a/47601952/4984832

    – SushiHangover
    Nov 28 '18 at 22:32













  • @SushiHangover I've done the adb testing, and think this is the issue: java.lang.RuntimeException: Unable to start receiver md527b6cae80f13bfed8573ffa181fefc60.BootReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=MyApp.MyApp/md527b6cae80f13bfed8573ffa181fefc60.AlertSyncService }: app is in background uid UidRecord{6ef4e91 u0a6 ... However, I don't know how to resolve this! Any ideas? I have tried running it with ContextCompat.StartForegroundService(...) But this has the same issue.

    – A.Davis
    Nov 29 '18 at 18:41













  • stackoverflow.com/questions/46445265/…

    – SushiHangover
    Nov 29 '18 at 20:23



















  • Top of my head without see the logcat output : [BroadcastReceiver(Enabled = true)] Review the testing (via adb) section of this answer: stackoverflow.com/a/47601952/4984832

    – SushiHangover
    Nov 28 '18 at 22:32













  • @SushiHangover I've done the adb testing, and think this is the issue: java.lang.RuntimeException: Unable to start receiver md527b6cae80f13bfed8573ffa181fefc60.BootReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=MyApp.MyApp/md527b6cae80f13bfed8573ffa181fefc60.AlertSyncService }: app is in background uid UidRecord{6ef4e91 u0a6 ... However, I don't know how to resolve this! Any ideas? I have tried running it with ContextCompat.StartForegroundService(...) But this has the same issue.

    – A.Davis
    Nov 29 '18 at 18:41













  • stackoverflow.com/questions/46445265/…

    – SushiHangover
    Nov 29 '18 at 20:23

















Top of my head without see the logcat output : [BroadcastReceiver(Enabled = true)] Review the testing (via adb) section of this answer: stackoverflow.com/a/47601952/4984832

– SushiHangover
Nov 28 '18 at 22:32







Top of my head without see the logcat output : [BroadcastReceiver(Enabled = true)] Review the testing (via adb) section of this answer: stackoverflow.com/a/47601952/4984832

– SushiHangover
Nov 28 '18 at 22:32















@SushiHangover I've done the adb testing, and think this is the issue: java.lang.RuntimeException: Unable to start receiver md527b6cae80f13bfed8573ffa181fefc60.BootReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=MyApp.MyApp/md527b6cae80f13bfed8573ffa181fefc60.AlertSyncService }: app is in background uid UidRecord{6ef4e91 u0a6 ... However, I don't know how to resolve this! Any ideas? I have tried running it with ContextCompat.StartForegroundService(...) But this has the same issue.

– A.Davis
Nov 29 '18 at 18:41







@SushiHangover I've done the adb testing, and think this is the issue: java.lang.RuntimeException: Unable to start receiver md527b6cae80f13bfed8573ffa181fefc60.BootReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=MyApp.MyApp/md527b6cae80f13bfed8573ffa181fefc60.AlertSyncService }: app is in background uid UidRecord{6ef4e91 u0a6 ... However, I don't know how to resolve this! Any ideas? I have tried running it with ContextCompat.StartForegroundService(...) But this has the same issue.

– A.Davis
Nov 29 '18 at 18:41















stackoverflow.com/questions/46445265/…

– SushiHangover
Nov 29 '18 at 20:23





stackoverflow.com/questions/46445265/…

– SushiHangover
Nov 29 '18 at 20:23












1 Answer
1






active

oldest

votes


















0














You could try this:



[BroadcastReceiver(Enabled = true, Exported = true, DirectBootAware = true)]
[IntentFilter(new string {
Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted, "android.intent.action.QUICKBOOT_POWERON"
})]
public class BootReceiver: BroadcastReceiver {
public override void OnReceive(Context context, Intent intent) {
//Do something
}
}





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528984%2fxamarin-android-start-service-on-boot-completed%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You could try this:



    [BroadcastReceiver(Enabled = true, Exported = true, DirectBootAware = true)]
    [IntentFilter(new string {
    Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted, "android.intent.action.QUICKBOOT_POWERON"
    })]
    public class BootReceiver: BroadcastReceiver {
    public override void OnReceive(Context context, Intent intent) {
    //Do something
    }
    }





    share|improve this answer




























      0














      You could try this:



      [BroadcastReceiver(Enabled = true, Exported = true, DirectBootAware = true)]
      [IntentFilter(new string {
      Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted, "android.intent.action.QUICKBOOT_POWERON"
      })]
      public class BootReceiver: BroadcastReceiver {
      public override void OnReceive(Context context, Intent intent) {
      //Do something
      }
      }





      share|improve this answer


























        0












        0








        0







        You could try this:



        [BroadcastReceiver(Enabled = true, Exported = true, DirectBootAware = true)]
        [IntentFilter(new string {
        Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted, "android.intent.action.QUICKBOOT_POWERON"
        })]
        public class BootReceiver: BroadcastReceiver {
        public override void OnReceive(Context context, Intent intent) {
        //Do something
        }
        }





        share|improve this answer













        You could try this:



        [BroadcastReceiver(Enabled = true, Exported = true, DirectBootAware = true)]
        [IntentFilter(new string {
        Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted, "android.intent.action.QUICKBOOT_POWERON"
        })]
        public class BootReceiver: BroadcastReceiver {
        public override void OnReceive(Context context, Intent intent) {
        //Do something
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 22:39









        navylovernavylover

        3,66031221




        3,66031221
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528984%2fxamarin-android-start-service-on-boot-completed%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks