I have an app which was built in api level 22, now I had to update it to api level 26 and the persistant notification that was built initially is no longer working. I have tried multiple codes from stackoverflow but with no success for me.
My code:
void setUpAsForeground(String text) {
Intent mainActivity = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent openMainActivity = PendingIntent.getActivity(getApplicationContext(), 0,
mainActivity, 0);
// Build the notification object.
mNotificationBuilder = new Notification.Builder(getApplicationContext())
.setSmallIcon(R.drawable.radio_icon_128px)
.setTicker(text)
.setWhen(0)
// .setWhen(System.currentTimeMillis())
.setContentTitle(getResources().getString(R.string.app_name) + text)
.setContentText(mMusicProvider.getCurrentSongTitle())
.setContentIntent(openMainActivity)
.setOngoing(true);
startForeground(NOTIFICATION_ID, mNotificationBuilder.build());
// broadcastAction(MainActivity.ACTION_UPDATE_TITLE);
}
any advice would be highly appreciated.