全屏通知

时间:2016-06-07 12:21:40

标签: android

我想创建一个全屏通知。我已使用以下代码获得通知。我需要做哪些更改才能使其成为全屏通知。

    private void showNotification(String data) {

    Intent i = new Intent(this, MapsActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("FCM Test")
            .setContentText(data)
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    manager.notify(0,builder.build());
}

4 个答案:

答案 0 :(得分:2)

您可以将简单通知转换为全屏通知,只需添加一行简单的代码builder.setFullScreenIntent(pendingIntent, true);以下是完整示例。我希望这段代码可以帮助你

全屏通知代码:

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(android.R.drawable.btn_star);
        builder.setContentTitle("This is title of notification");
        builder.setContentText("This is a notification Text");
        builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));

        Intent intent = new Intent(Broadcastdemo.this, ThreadDemo.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 113,intent, PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setContentIntent(pendingIntent);
        builder.setAutoCancel(true);

        builder.setFullScreenIntent(pendingIntent, true);


        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(115, builder.build()); 

答案 1 :(得分:1)

在您的构建器上,sap.m.MaskInput之前 只需添加以下行:setContentIntent(pendingIntent);

答案 2 :(得分:0)

尝试添加SetStyleSetPriorityas,如下所示:(它对我来说很好)

  .SetStyle(new Notification.BigTextStyle().BigText(message.Long_Message))   
  .SetPriority((int)NotificationPriority.Max)

答案 3 :(得分:-1)

  

如果通知的优先级被标记为高,最大或全屏,   它得到了提醒通知。

您需要使用

.setPriority(Notification.PRIORITY_MAX)

您可以参考this repo获取单挑/全屏通知的完整示例