Im making a SoftPhone App, and right now im facing the issue that my Service Notification is not enabled by default is there a way to enable it by default or ask the user for permission to enable it without making an intent to access settings?
Edit:
My service in my manifest:
<service
android:name=".Service"
android:label="PBXService"/>
I start this service like this:
startService(new Intent(ACTION_MAIN).setClass(this, Service.class));
Inside the service i show the service notification like this:
mNotif = Compatibility.createNotification(this, mNotificationTitle, "Phone service", R.mipmap.ic_launcher, R.mipmap.ic_launcher, bm, mNotifContentIntent, true, notifcationsPriority);
//mNM is my notification manager.
mNM.notify(id, mNotif);
Compatibility class method:
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
return ApiTwentySixPlus.createSimpleNotification(context, title, text, intent);
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
return ApiTwentyOnePlus.createSimpleNotification(context, title, text, intent);
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
return ApiSixteenPlus.createSimpleNotification(context, title, text, intent);
} else {
return ApiElevenPlus.createSimpleNotification(context, title, text, intent);
}
}
In Api26+ Class:
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.linphone_logo)
.setAutoCancel(true)
.setContentIntent(intent)
.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE)
.setCategory(Notification.CATEGORY_MESSAGE)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
.setColorized(true)
.setColor(context.getColor(R.color.notification_color_led))
.build();
return notif;
}
Phone model: SM-J737A
Android version: 8.0.0
I know for a fact that this works because whenever the permission is manually activated i have no issues with this.