android - 解析推送 - 如何在 Android 上接收推送时自动打开 Activity 而无需用户操作

标签 android push-notification push parse-platform google-cloud-messaging

我有一个要求(android),当用户没有点击系统托盘中的通知而收到推送通知时,我的应用程序应该自动运行其主要 Activity 。我有一张显示当前位置的 map ,但在推送中,我会收到一个位置,我需要在主要 Activity 中使用我的 map ,以便在收到推送时将相机移动到当前收到的位置,并提醒用户自定义声音。所有这一切都应该在用户不点击任何东西的情况下发生。请帮助。提前致谢。

最佳答案

是的,这是可能的。 Parse.com 文档说:

You can also specify an Intent to be fired in the background when the push notification is received. This will allow your app to perform custom handling for the notification, and can be used whether or not you have chosen to display a system tray message. To implement custom notification handling, set the Action entry in your push notification data dictionary to the Intent action which you want to fire. Android guidelines suggest that you prefix the action with your package name to avoid namespace collisions with other running apps.

因此您以这种方式发送推送通知:

JSONObject data = new JSONObject("{\"action\": \"com.example.UPDATE_STATUS\""}));

ParsePush push = new ParsePush();
push.setData(data);
push.sendPushInBackground();

然后在您的 AndroidManifest.xml 中注册一个广播接收器,只要收到带有 com.example.UPDATE_STATUS 操作参数的推送通知,该接收器就会被调用:

<receiver android:name="com.example.MyBroadcastReceiver" android:exported="false">
  <intent-filter>
    <action android:name="com.example.UPDATE_STATUS" />
  </intent-filter>
</receiver>

在您的广播接收器中,您可以开始一个新 Activity :

public class MyBroadcastReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    context.startActivity(new Intent(context, MyActivity.class));
  }
}

关于android - 解析推送 - 如何在 Android 上接收推送时自动打开 Activity 而无需用户操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22204326/

相关文章:

android - 在 Android App 中信任自签名证书

android - 在 Android 中连接到指定的 WiFi 网络

android - 更改 Android 微调器布局/设计

php - 如何使用 v1 API 将 FCM 通知发送到特定设备 token 列表

android - 如何防止 Firebase Cloud Messaging (FCM) 中的重复通知

android - 在 AsyncTask 中同时使用 POST 和 GET http 请求

windows-phone-8 - Windows Phone 公司应用的无配额推送通知

perl - 在 For 循环中推送函数以创建许多新数组

cordova - 当应用程序打开或应用程序在后台时,Phonegap Firebase 推送通知不会触发事件监听器

ios - 如何使用 swift 从 launchOptions 获取自定义推送通知值?