【问题标题】:NotificationCompat and setFullScreenIntent()NotificationCompat 和 setFullScreenIntent()
【发布时间】:2015-02-17 06:55:22
【问题描述】:

我想知道是否有人对这种类型的通知有一些经验。

在我的用例中,我想从我的服务触发通知,然后它应该打开一个全屏视频。方法 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;
}

【问题讨论】:

  • 你有没有找到解决这个问题的方法?

标签: android android-intent service android-notifications


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    尝试删除

    .setContentIntent(contentIntent)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多