以编程方式将android应用程序从后台带回

s6fujrry  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(267)

我对android编码还不熟悉,但我已经玩过java了。
我想打开或带回我的应用程序,一旦它是在后台。
我到处找了找,但似乎什么都没用。
我有一个类的函数,它在每次收到通知时都被调用,它是cordovanotificationreceivedhandler,由onesignal init按照下面的代码示例化。

  1. OneSignal.init(this.cordova.getActivity(),
  2. googleProjectNumber,
  3. appId,
  4. new CordovaNotificationOpenedHandler(notifOpenedCallbackContext),
  5. new CordovaNotificationReceivedHandler(notifReceivedCallbackContext)
  6. );

为了使我的应用程序重新排序和显示,即使用户在另一个应用程序中,我也做了以下更改:

  1. OneSignal.init(this.cordova.getActivity(),
  2. googleProjectNumber,
  3. appId,
  4. new CordovaNotificationOpenedHandler(notifOpenedCallbackContext),
  5. new CordovaNotificationReceivedHandler(this.cordova.getActivity(), notifReceivedCallbackContext));

在接收推送通知时调用的函数体中,我添加了以下代码:

  1. Intent it = new Intent("intent.my.action");
  2. it.setComponent(new ComponentName(contextActivy.getPackageName(), MainActivity.class.getName()));
  3. it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  4. contextActivy.getApplicationContext().startActivity(it);
  5. this.handleActivityLifecycleHandler();

科莫一级公寓ó这是一个修改çã收件人:

  1. private class CordovaNotificationReceivedHandler implements NotificationReceivedHandler {
  2. private CallbackContext jsNotificationReceivedCallBack;
  3. private Context contextActivy;
  4. public CordovaNotificationReceivedHandler(Context contextActivy, CallbackContext inCallbackContext) {
  5. jsNotificationReceivedCallBack = inCallbackContext;
  6. this.contextActivy = contextActivy;
  7. }
  8. @Override
  9. public void notificationReceived(OSNotification notification) {
  10. Log.w("Got here","Aqui");
  11. Intent it = new Intent("intent.my.action");
  12. it.setComponent(new ComponentName(contextActivy.getPackageName(), MainActivity.class.getName()));
  13. it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  14. contextActivy.getApplicationContext().startActivity(it);
  15. this.handleActivityLifecycleHandler();
  16. try {
  17. CallbackHelper.callbackSuccess(jsNotificationReceivedCallBack, new JSONObject(notification.stringify()));
  18. }
  19. catch (Throwable t) {
  20. t.printStackTrace();
  21. }
  22. }
  23. }

问题是应用程序没有重新排序以应用或打开。
重要的是要记住,我假设应用程序应该是开放的。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题