在我的应用程序中,我能够在日志中看到它的到来,直到接收方法,但通知没有触发。
String message = intent.getStringExtra(Constants.NOTIFICATION_MSG);
String title = intent.getStringExtra(Constants.NOTIFICATION_TITLE);
int notificationId = intent.getIntExtra(Constants.NOTIFICATION_ID, 0);
if (BuildConfig.DEBUG) {
Log.e(TAG,"onReceive !! called "+notificationId);
}
if(TextUtils.isEmpty(title)|| TextUtils.isEmpty(message))return;
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notifyIntent = new Intent(context,GoalHomeScreen.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), notifyIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(title);
builder.setContentText(message);
builder.setContentIntent(pendingIntent);
builder.setSmallIcon(R.drawable.ic_app);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
builder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
if (Utils.getUpdateNotification()) {
notificationManager.notify(notificationId, notification);
}