Aks*_*iom 9 service android android-intent android-notifications
我想知道是否有人对这种类型的通知有一些经验.
在我的用例中,我想触发来自我的服务的通知,而不是应该打开全屏视频.方法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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2877 次 |
| 最近记录: |