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.

add a comment |
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.

add a comment |
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.

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.


edited Nov 19 at 11:44
Ali
1,4192929
1,4192929
asked Nov 19 at 11:41
Snehal Gongle
205212
205212
add a comment |
add a comment |
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());
}
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
add a comment |
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());
}
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
add a comment |
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());
}
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
add a comment |
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());
}
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());
}
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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