[英]Get action in Push Notification when App in background
當應用程序在后台時如何在推送通知中執行操作? 我在Android Oreo中使用此功能時,后台運行應用程序時會出現一些問題。
我在后台服務中使用它。 我已經在模擬器中進行了測試,但沒有在真實設備中進行過測試。 檢查這是否對您有用。
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);
另外,如果您想顯示一個活動,則在設備鎖定時,將其放在活動onCreate()中,這應該可以工作。 一件事,當它不起作用時,是顯示來電/去電屏幕
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setContentView(...);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.