解析推送 - 如何在 Android 上接收推送时无需用户操作即可自动打开活动 [英] Parse Push - How to Automatically Open an activity without user action on receiving a push on Android

查看:24
本文介绍了解析推送 - 如何在 Android 上接收推送时无需用户操作即可自动打开活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a requirement (android) where my app should run its main activity automatically when a push notification is received without the user clicking on notification in system tray. I am having a map where it shows current location, but in the push, i will receive a location, and i need my map in the main activity to move the camera to the currently received location on receiving the push, and alert the user with a custom sound. All this should happen without the user clicking on anything. Pls help. Thanks in advance.

推荐答案

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

Yes, it's possible. Parse.com documentation says:

您还可以指定在推送通知时在后台触发的 Intent已收到.这将允许您的应用程序对通知执行自定义处理,并且无论您是否选择显示系统托盘消息,都可以使用.实施自定义通知处理,在您的推送通知数据中设置 Action 条目字典到您要触发的 Intent 操作.Android 指南建议你用你的包名作为动作的前缀,以避免与其他的命名空间冲突运行应用.

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.

所以你以这种方式发送推送通知:

So you send push notifications in this way:

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

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

然后在您的 AndroidManifest.xml 中注册一个广播接收器,每当收到带有 com.example.UPDATE_STATUS 的 action 参数的推送通知时都会调用该接收器:

Then in your AndroidManifest.xml register a broadcast receiver that will be called whenever a push notification is received with an action parameter of 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>

在您的广播接收器中,您可以开始一项新活动:

In your broadcast receiver you can start a new activity:

public class MyBroadcastReceiver extends BroadcastReceiver {

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

这篇关于解析推送 - 如何在 Android 上接收推送时无需用户操作即可自动打开活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆