![](/img/trans.png)
[英]Push notification from Mixpanel dashboard to Android Cordova app
[英]Start Cordova app from Android notification
我建立了一個Cordova應用,可在Android上顯示通知。 當單擊通知並同時關閉應用程序時,我希望再次啟動該應用程序(cordova活動)。
這是我在Cordova Android插件中構建通知的方式:
Context context = this.cordova.getActivity();
Intent resultIntent = new Intent(context, CordovaActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
Notification noti = new Notification.Builder(context)
.setContentTitle("MyApp")
.setContentText("foobar")
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
該通知會正確顯示,但是單擊它時不會啟動我的應用程序。 我不確定要為Intent提供什么課程。
我必須如何創建通知才能使其正常工作?
該問題的副本,您只需用您的包裹名稱替換
解決方案是將MainActivity.class
用於意圖(而不是CordovaActivity類)。 可以在名為小部件ID的包中找到(並且必須將其導入),該包在您的Cordova項目的config.xml
中定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.