我收到显示的推送通知,然后立即自动被解雇。我想这样,所以用户必须手动关闭它或点击它去转到应用程序。非常感谢任何帮助。
private void sendNotification(Bundle msg, final int notID) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent myintent = new Intent(this, Main.class);
myintent.putExtras(msg);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
myintent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentIntent(contentIntent);
mBuilder.setTicker(myintent.getStringExtra("ticker"));
mBuilder.setContentText(myintent.getStringExtra("contentText"));
mBuilder.setContentTitle(myintent.getStringExtra("contentTitle"));
mBuilder.setWhen(System.currentTimeMillis());
mBuilder.setAutoCancel(false);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
答案 0 :(得分:2)
尝试使用此代码。 PendingIntent和setAutoCancel只是差别很小。
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, HomeScreen.class), 0);
builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification_icon)
.setContentTitle(getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setSound(customSoundURI).setAutoCancel(true)
.setContentText(msg);
builder.setContentIntent(contentIntent);