I’m having trouble seeing any notifications with a targetSdkVersion 26. When I get a new result there is a log statement, but no notification.
I’ve added a channel to the NotificationManager, but that doesn’t seem to do anything.
The only other log statements are: W/Notification: Use of stream types is deprecated for operations other than volume control W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
My code in onHandleIntent(Intent) in PollService.java:
...
Log.i(TAG, "Got a new result " + resultId);
String CHANNEL_ID = "channel_1";
Resources resources = getResources();
Intent i = PhotoGalleryActivity.newIntent(this);
PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel mChannel;
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setTicker(resources.getString(R.string.new_pictures_title))
.setSmallIcon(android.R.drawable.ic_menu_report_image)
.setContentTitle(resources.getString(R.string.new_pictures_title))
.setContentText(resources.getString(R.string.new_pictures_text))
.setContentIntent(pi);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel(CHANNEL_ID, this.getString(R.string.app_name), importance);
// Configure the notification channel.
mChannel.setDescription("notification");
mNotificationManager.createNotificationChannel(mChannel);
} else {
builder.setContentTitle(resources.getString(R.string.new_pictures_title))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true);
}
builder.setChannel(CHANNEL_ID);
mNotificationManager.notify(0, builder.build());
Guys, if anyone has troubles with Oreo notifications in background (when app is not opened or device is blocked), there is Evernote library I used in 28-29 Chapters to do the same thing as in the book. Here is the solution: https://github.com/bekabot/PhotoGallery/tree/Chapter-29-with-Evernote
I am having the same problem, no notifications come through, I even added a second one with different text and title values to see if a Notification would appear, and nothing. I am getting the log messages though. Can anyone help?