简体   繁体   English

当应用程序在后台时,可以在推送通知中执行操作

[英]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.

相关问题 当应用在后台时推送通知 - Push notification when app is in background 当应用程序在后台时更新Firebase推送通知 - Updating Firebase push notification when app is in background 仅当应用程序在后台时发送推送通知 - Sending a push notification only when app is in background 当应用程序在后台时,Cordova推送通知不起作用 - Cordova push notification not working when app is in background 当应用程序不在后台时,推送通知服务未运行 - Push Notification Service is not running when the app is not in the background 当应用程序不在后台运行时,推送通知未收到 - Push notification not receiving when app not running on background 当应用程序处于后台时发送鸟推送通知 - Sendbird push notification when app is in background 当应用程序在Android TV上处于后台时推送通知 - Push notification when app is in the background on Android TV 用户单击通知启动后台应用程序时如何获取Android推送通知有效负载 - How to get Android push notification payload when background App is launched by user click on notification 当应用程序在android中处于后台时,通知图标不可见(Gcm推送通知)? - Notification Icon not visible (Gcm Push notification) when app is in background in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM