Quantcast
Viewing all articles
Browse latest Browse all 42

Change Foreground notification

I have a Foreground service working in the background of my app with working notification,However,I want to customize my own notification.

This is the default notification picture:https://ibb.co/TqRL9q8

I tired to change the notification from this:

    @Overridepublic void onCreate() {    super.onCreate();    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O)        startMyOwnForeground();    else{    startForeground(1, new Notification());    }}

To that:

@Overridepublic void onCreate() {    super.onCreate();    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O)        startMyOwnForeground();    else{    Intent intent = new Intent(this, BackgroundLocation.class);    // The PendingIntent that leads to a call to onStartCommand() in this service.    PendingIntent servicePendingIntent = PendingIntent.getService(this, 0, intent,            PendingIntent.FLAG_UPDATE_CURRENT);    // The PendingIntent to launch activity.    PendingIntent activityPendingIntent = PendingIntent.getActivity(this, 0,            new Intent(this, MainActivity.class), 0);    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_launch, getString(R.string.launch_activity), activityPendingIntent);    NotificationCompat.Action action2 = new NotificationCompat.Action(R.drawable.ic_cancel, getString(R.string.remove_location_updates), servicePendingIntent);    Notification notification = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID)            .setContentTitle("App is running in background")            .addAction(action)            .addAction(action2)            .setPriority(NotificationManager.IMPORTANCE_HIGH)            .setCategory(Notification.CATEGORY_SERVICE)            .setSmallIcon(R.drawable.letherknowtitle)            .build();    startForeground(1, notification);    }}

When using the code above the notification isn't changing. However when user sdk > android o the notification is changing.

Thanks for your help.


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>