解析推 - 如何在没有用户的操作自动打开活动上接受Android上推 [英] Parse Push - How to Automatically Open an activity without user action on receiving a push on Android

查看:130
本文介绍了解析推 - 如何在没有用户的操作自动打开活动上接受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在后台被解雇时,推送通知是
  好评。这将使您的应用程序执行自定义处理的通知,并
  可用于无论是否选择了显示系统托盘消息。为了实现
  自定义通知的处理,您在您的推送通知的数据录入行动
  词典要火意图的行动。 Android的指南建议,
  您preFIX您的包名的行动,以避免与其他命名空间冲突
  正在运行的应用。

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();

然后在你的Andr​​oidManifest.xml中注册一个广播接收器,只要用com.example.UPDATE_STATUS的操作参数收到一个推送通知将被调用:

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天全站免登陆