【问题标题】:FullScreen Notification全屏通知
【发布时间】:2016-06-07 12:21:40
【问题描述】:

我想创建一个全屏通知。我通过使用以下代码实现了通知。我需要进行哪些更改才能使其成为全屏通知。

    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());
}

【问题讨论】:

    标签: android


    【解决方案1】:

    您可以将简单通知转换为全屏通知,只需添加一行简单的代码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()); 
    

    【讨论】:

    • 是的,这应该是正确的答案。它仍然适用于 Android 10(测试版 6)
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      尝试将setStylesetPriority 添加如下:(对我来说很好)

        .setStyle(new Notification.BigTextStyle().BigText(message.Long_Message))   
        .setPriority((int)NotificationPriority.Max)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-05
        • 1970-01-01
        • 2021-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多