Enable My Background Service Notification Pragmatically











up vote
0
down vote

favorite












I'm having android application that i have to run in background using services for android o and above i know that background services are killed by system so i'm using startForground with proper notifications but sometimes these notification do not appear and it may be because of mobile settings



so if we go from




Settings->App->My App Name->Notifications->My Background Services &
Services




hence my question is how do i start or check these My Background Services & Services pragmatically.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm having android application that i have to run in background using services for android o and above i know that background services are killed by system so i'm using startForground with proper notifications but sometimes these notification do not appear and it may be because of mobile settings



    so if we go from




    Settings->App->My App Name->Notifications->My Background Services &
    Services




    hence my question is how do i start or check these My Background Services & Services pragmatically.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm having android application that i have to run in background using services for android o and above i know that background services are killed by system so i'm using startForground with proper notifications but sometimes these notification do not appear and it may be because of mobile settings



      so if we go from




      Settings->App->My App Name->Notifications->My Background Services &
      Services




      hence my question is how do i start or check these My Background Services & Services pragmatically.










      share|improve this question















      I'm having android application that i have to run in background using services for android o and above i know that background services are killed by system so i'm using startForground with proper notifications but sometimes these notification do not appear and it may be because of mobile settings



      so if we go from




      Settings->App->My App Name->Notifications->My Background Services &
      Services




      hence my question is how do i start or check these My Background Services & Services pragmatically.







      android background-service






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 11:44









      Ali

      1,4192929




      1,4192929










      asked Nov 19 at 11:41









      Snehal Gongle

      205212




      205212
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          From Android O,



          We need to set channel id for each notification arrived in background.




          You can check latest firebase implementation here.




          In manifest need to add



          <meta-data
          android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="default_channel_id"/>


          And in your Messaging service class,



           @Override
          public void onMessageReceived(RemoteMessage remoteMessage) {
          sendNotification(remoteMessage.getNotification().getBody());//Considering you have message in your body.
          }


          And



          private void sendNotification(String messageBody) {
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
          PendingIntent.FLAG_ONE_SHOT);

          String channelId = getString(R.string.default_notification_channel_id);
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this, channelId)
          .setSmallIcon(R.drawable.ic_stat_ic_notification)
          .setContentTitle(getString(R.string.fcm_message))
          .setContentText(messageBody)
          .setAutoCancel(true)
          .setSound(defaultSoundUri)
          .setContentIntent(pendingIntent);

          NotificationManager notificationManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          // Since android Oreo notification channel is needed.
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel(channelId,
          "Channel human readable title",
          NotificationManager.IMPORTANCE_DEFAULT);
          notificationManager.createNotificationChannel(channel);
          }

          notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
          }





          share|improve this answer





















          • thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
            – Snehal Gongle
            Nov 19 at 13:40










          • I don't think so, that background service is permission based in android. Please share any link or logic related your question.
            – Anil Ghodake
            2 days ago










          • I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
            – Anil Ghodake
            2 days ago













          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',
          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%2f53373884%2fenable-my-background-service-notification-pragmatically%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








          up vote
          0
          down vote













          From Android O,



          We need to set channel id for each notification arrived in background.




          You can check latest firebase implementation here.




          In manifest need to add



          <meta-data
          android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="default_channel_id"/>


          And in your Messaging service class,



           @Override
          public void onMessageReceived(RemoteMessage remoteMessage) {
          sendNotification(remoteMessage.getNotification().getBody());//Considering you have message in your body.
          }


          And



          private void sendNotification(String messageBody) {
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
          PendingIntent.FLAG_ONE_SHOT);

          String channelId = getString(R.string.default_notification_channel_id);
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this, channelId)
          .setSmallIcon(R.drawable.ic_stat_ic_notification)
          .setContentTitle(getString(R.string.fcm_message))
          .setContentText(messageBody)
          .setAutoCancel(true)
          .setSound(defaultSoundUri)
          .setContentIntent(pendingIntent);

          NotificationManager notificationManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          // Since android Oreo notification channel is needed.
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel(channelId,
          "Channel human readable title",
          NotificationManager.IMPORTANCE_DEFAULT);
          notificationManager.createNotificationChannel(channel);
          }

          notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
          }





          share|improve this answer





















          • thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
            – Snehal Gongle
            Nov 19 at 13:40










          • I don't think so, that background service is permission based in android. Please share any link or logic related your question.
            – Anil Ghodake
            2 days ago










          • I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
            – Anil Ghodake
            2 days ago

















          up vote
          0
          down vote













          From Android O,



          We need to set channel id for each notification arrived in background.




          You can check latest firebase implementation here.




          In manifest need to add



          <meta-data
          android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="default_channel_id"/>


          And in your Messaging service class,



           @Override
          public void onMessageReceived(RemoteMessage remoteMessage) {
          sendNotification(remoteMessage.getNotification().getBody());//Considering you have message in your body.
          }


          And



          private void sendNotification(String messageBody) {
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
          PendingIntent.FLAG_ONE_SHOT);

          String channelId = getString(R.string.default_notification_channel_id);
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this, channelId)
          .setSmallIcon(R.drawable.ic_stat_ic_notification)
          .setContentTitle(getString(R.string.fcm_message))
          .setContentText(messageBody)
          .setAutoCancel(true)
          .setSound(defaultSoundUri)
          .setContentIntent(pendingIntent);

          NotificationManager notificationManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          // Since android Oreo notification channel is needed.
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel(channelId,
          "Channel human readable title",
          NotificationManager.IMPORTANCE_DEFAULT);
          notificationManager.createNotificationChannel(channel);
          }

          notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
          }





          share|improve this answer





















          • thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
            – Snehal Gongle
            Nov 19 at 13:40










          • I don't think so, that background service is permission based in android. Please share any link or logic related your question.
            – Anil Ghodake
            2 days ago










          • I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
            – Anil Ghodake
            2 days ago















          up vote
          0
          down vote










          up vote
          0
          down vote









          From Android O,



          We need to set channel id for each notification arrived in background.




          You can check latest firebase implementation here.




          In manifest need to add



          <meta-data
          android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="default_channel_id"/>


          And in your Messaging service class,



           @Override
          public void onMessageReceived(RemoteMessage remoteMessage) {
          sendNotification(remoteMessage.getNotification().getBody());//Considering you have message in your body.
          }


          And



          private void sendNotification(String messageBody) {
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
          PendingIntent.FLAG_ONE_SHOT);

          String channelId = getString(R.string.default_notification_channel_id);
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this, channelId)
          .setSmallIcon(R.drawable.ic_stat_ic_notification)
          .setContentTitle(getString(R.string.fcm_message))
          .setContentText(messageBody)
          .setAutoCancel(true)
          .setSound(defaultSoundUri)
          .setContentIntent(pendingIntent);

          NotificationManager notificationManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          // Since android Oreo notification channel is needed.
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel(channelId,
          "Channel human readable title",
          NotificationManager.IMPORTANCE_DEFAULT);
          notificationManager.createNotificationChannel(channel);
          }

          notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
          }





          share|improve this answer












          From Android O,



          We need to set channel id for each notification arrived in background.




          You can check latest firebase implementation here.




          In manifest need to add



          <meta-data
          android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="default_channel_id"/>


          And in your Messaging service class,



           @Override
          public void onMessageReceived(RemoteMessage remoteMessage) {
          sendNotification(remoteMessage.getNotification().getBody());//Considering you have message in your body.
          }


          And



          private void sendNotification(String messageBody) {
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
          PendingIntent.FLAG_ONE_SHOT);

          String channelId = getString(R.string.default_notification_channel_id);
          Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this, channelId)
          .setSmallIcon(R.drawable.ic_stat_ic_notification)
          .setContentTitle(getString(R.string.fcm_message))
          .setContentText(messageBody)
          .setAutoCancel(true)
          .setSound(defaultSoundUri)
          .setContentIntent(pendingIntent);

          NotificationManager notificationManager =
          (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          // Since android Oreo notification channel is needed.
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel(channelId,
          "Channel human readable title",
          NotificationManager.IMPORTANCE_DEFAULT);
          notificationManager.createNotificationChannel(channel);
          }

          notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 12:22









          Anil Ghodake

          7721233




          7721233












          • thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
            – Snehal Gongle
            Nov 19 at 13:40










          • I don't think so, that background service is permission based in android. Please share any link or logic related your question.
            – Anil Ghodake
            2 days ago










          • I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
            – Anil Ghodake
            2 days ago




















          • thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
            – Snehal Gongle
            Nov 19 at 13:40










          • I don't think so, that background service is permission based in android. Please share any link or logic related your question.
            – Anil Ghodake
            2 days ago










          • I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
            – Anil Ghodake
            2 days ago


















          thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
          – Snehal Gongle
          Nov 19 at 13:40




          thanks for the response but that is not my question, my question is how Settings->App->My App Name->Notifications->My Background Services & Services check these two pragmatically
          – Snehal Gongle
          Nov 19 at 13:40












          I don't think so, that background service is permission based in android. Please share any link or logic related your question.
          – Anil Ghodake
          2 days ago




          I don't think so, that background service is permission based in android. Please share any link or logic related your question.
          – Anil Ghodake
          2 days ago












          I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
          – Anil Ghodake
          2 days ago






          I know, from version greater than Android O (26), documentation suggesting that use schedule job instead of background service. But in case of FCM not mentioned any kind of permission module related to background message service implementation. If you suggest any logic or scenario in that case I can help you and I can also know new FCM implementation.
          – Anil Ghodake
          2 days ago




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373884%2fenable-my-background-service-notification-pragmatically%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

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          Npm cannot find a required file even through it is in the searched directory