我试图在三星Galaxy S7(Android 8.0)上测试我的应用程序,但通知没有出现。我已经检查过应用程序权限和电池设置,还有什么其他的可能性?
public void sendNotification(View view)
{
@SuppressWarnings("deprecation")
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
//creating the intent that’ll fire when the user taps the notification
Intent intent = new Intent(getApplicationContext(), ViewActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
mBuilder.setContentIntent(pendingIntent);
//making notification disappear after being clicked
mBuilder.setAutoCancel(true);
mBuilder.setSmallIcon(R.drawable.notification_icon);
mBuilder.setContentTitle("TI connect");
mBuilder.setContentText("New report has been added! Total reports: " + repNo);
mBuilder.setPriority(Notification.PRIORITY_MAX);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(001, mBuilder.build());
}
NotificationCompat
的新Builder
。https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder#notificationcompatbuilder - Crammeur