繁体   English   中英

从Android通知启动Cordova应用

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM