[英]Get action in Push Notification when App in background
How to get action in Push Notification when App in background?. 当应用程序在后台时如何在推送通知中执行操作? I am using this functionality in Android Oreo getting some issue when app in background.
我在Android Oreo中使用此功能时,后台运行应用程序时会出现一些问题。
I'm using this in background services. 我在后台服务中使用它。 I'm tested that in emulator, but not in real device.
我已经在模拟器中进行了测试,但没有在真实设备中进行过测试。 Check does this will work for you.
检查这是否对您有用。
NotificationCompat.Builder builder = ...;
Intent intent = new Intent(context, YourActivity.class);
intent.putExtra(you can put extras);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
0);
builder.setContentIntent(contentIntent);
Also, if you'd like to show an activity, when device is locked, put this in your activity onCreate(), this should work. 另外,如果您想显示一个活动,则在设备锁定时,将其放在活动onCreate()中,这应该可以工作。 One thing, when this doesn't work, is when a incoming/outgoing call screen is shown
一件事,当它不起作用时,是显示来电/去电屏幕
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setContentView(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.