通知自动打开,无需任何点击
Notification automatically opens up without any click
通知一经发布即打开,无需用户进行任何操作。
这是我的代码:
private void sendNotification(String message,String title,String id,String book) {
smLocalStore=new SMLocalStore(this);
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Log.i("id:",id);
intent.putExtra("id",id);
intent.putExtra("val","1");
intent.putExtra("book",book);
int requestCode = 0;
//notification sending
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
.setSound(sound)
.setSmallIcon(R.mipmap.ic_lau)
.setLargeIcon(largeIcon)
.setContentTitle(title)
.setFullScreenIntent(pendingIntent,true)
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(x, noBuilder.build()); //0 = ID of notification
}
从您的代码中删除以下行:
.setFullScreenIntent(pendingIntent,true)
Android Developer Documentation 说:
setFullScreenIntent(PendingIntent intent, boolean highPriority)
An intent to launch instead of posting the notification to the status bar.
通知一经发布即打开,无需用户进行任何操作。
这是我的代码:
private void sendNotification(String message,String title,String id,String book) {
smLocalStore=new SMLocalStore(this);
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Log.i("id:",id);
intent.putExtra("id",id);
intent.putExtra("val","1");
intent.putExtra("book",book);
int requestCode = 0;
//notification sending
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
.setSound(sound)
.setSmallIcon(R.mipmap.ic_lau)
.setLargeIcon(largeIcon)
.setContentTitle(title)
.setFullScreenIntent(pendingIntent,true)
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(x, noBuilder.build()); //0 = ID of notification
}
从您的代码中删除以下行:
.setFullScreenIntent(pendingIntent,true)
Android Developer Documentation 说:
setFullScreenIntent(PendingIntent intent, boolean highPriority)
An intent to launch instead of posting the notification to the status bar.