抬头通知在几秒钟之后被解雇

时间:2016-08-25 11:32:31

标签: android android-notifications heads-up-notifications

我试图通过下面的代码提出抬头通知,并希望它持续到用户决定解雇它为止。但它会在几秒钟后(大约10秒钟)自动被解雇。有没有办法让它持久化并留给用户解雇它。

{{1}}

1 个答案:

答案 0 :(得分:4)

此代码段对我有用。

        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent piDismiss = PendingIntent.getActivity(this, 0, intent, 0);

        //build notification
        NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
        .setCategory(Notification.CATEGORY_MESSAGE)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Ping Notification")
        .setContentText("You have a new notification.")
        .setDefaults(Notification.DEFAULT_ALL) // must requires VIBRATE permission
        .setPriority(NotificationCompat.PRIORITY_DEFAULT) //must give priority to High, Max which will considered as heads-up notification
        .addAction(R.drawable.dismiss,
        "View Call", piDismiss)
        .addAction(R.drawable.ic_ok,
        "ok", null)
        .setFullScreenIntent(piDismiss, true);