通知会自动打开,无需任何点击

时间:2016-08-10 18:15:50

标签: android android-notifications

通知会在发布后立即打开,不需要用户执行任何操作。

这是我的代码:

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
}

1 个答案:

答案 0 :(得分:2)

从代码中删除以下行:

.setFullScreenIntent(pendingIntent,true)

Android Developer Documentation说:

  

setFullScreenIntent(PendingIntent intent, boolean highPriority)

     

意图启动而不是将通知发布到状态栏。