NotificationCompat和setFullScreenIntent()

16

我想知道是否有人有使用这种类型通知的经验。

在我的用例中,我希望从我的服务触发通知,然后它应该打开全屏视频。方法setFullScreenIntent似乎正是解决这个问题的正确方式,因为文档中写道:

一个意图,用于启动而不是将通知发布到状态栏。仅供需要用户立即注意的极高优先级通知使用,例如用户明确设置到特定时间的来电或闹钟。

所以它说它的工作方式就像来电一样。这意味着即使我的手机处于睡眠状态,我也应该能够看到全屏通知。

但在我的情况下,我只收到悬浮通知,如果我点击它,它会打开活动。虽然在文档中他们提到了这种行为 ...

在某些平台上,系统UI可能会选择在用户正在使用设备时显示悬浮通知,而不是启动此意图。

... 我想知道如何在触发通知时自动打开活动。就像来电屏幕一样。

这是我的服务代码:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {


    Intent notificationIntent = new Intent("android.intent.category.LAUNCHER");
    intent.setClassName("com.example.test",
            "com.example.test.VideoActivity");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentIntent(contentIntent)
                .setContentTitle("Video")
                .setContentText("Play video")
                .setFullScreenIntent(contentIntent, true);

    NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);



    mNotificationManager.notify(0, mBuilder.build());

    return Service.START_STICKY;
}

3
你是否曾经找到了解决这个问题的方法? - splangi
2个回答

0
尝试在onCreate中使用setFullScreenIntent通知通知。
@Override
public int onCreate() {
    Intent notificationIntent = new Intent("android.intent.category.LAUNCHER");
    intent.setClassName("com.example.test",
        "com.example.test.VideoActivity");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(contentIntent)
            .setContentTitle("Video")
            .setContentText("Play video")
            .setFullScreenIntent(contentIntent, true);

    NotificationManager mNotificationManager = (NotificationManager) 
   this.getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(0, mBuilder.build());
}

-3
尝试移除

标签。

.setContentIntent(contentIntent)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接