我正在寻找帮助,找出如何使用Parse Push为Android(Java)设置此功能。
使用以下内容发送推送:{ "alert": "Read this", "articleId": "2" }
该应用将打开:myCoolAdress.com/articles/2
编辑:添加了代码。
公共类ParseBroadcastReceiver扩展了BroadcastReceiver {
public static final String ACTION = "org.app.app.MESSAGE";
public static final String PARSE_EXTRA_DATA_KEY = "com.parse.Data";
public static final String PARSE_JSON_CHANNEL_KEY = "com.parse.Channel";
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String articleId = extras != null ? extras
.getString("com.parse.Data") : "";
JSONObject jObject;
try {
jObject = new JSONObject(articleId);
Log.d("Log",
jObject.getString("articleId")
+ jObject.getString("action"));
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
答案 0 :(得分:0)
您可以执行以下操作:
BroadcastListener
收到推送通知时,请提取有效负载。Notification
。PendingIntent
添加到通过您的网址指向浏览器的通知中。http://developer.android.com/guide/topics/ui/notifiers/notifications.html
因此,如果用户点击您的通知,他将被重定向到您的网站。
答案 1 :(得分:0)
您是否按照https://parse.com/docs/android/guide#push-notifications中的说明进行操作?名为" Receiving Pushes"有关于如何处理推送通知的信息。
答案 2 :(得分:0)
我找到了解决方案
public static final String ACTION = "org.APP.APP.MESSAGE";
public static final String PARSE_EXTRA_DATA_KEY = "com.parse.Data";
public static final String PARSE_JSON_CHANNEL_KEY = "com.parse.Channel";
public static final String TAG = "articleId";
@Override
//
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String jsonData = extras.getString( "com.parse.Data" );
JSONObject jObject;
Log.i("PUSH", String.format("push received: %s", jsonData));
try {
jObject = new JSONObject(jsonData);
String articleId = jObject.getString("articleId");
Log.d("PUSH URL",
"http://MYaweSOMEapp.com/articles/" + articleId);
Intent webViewIntent = new Intent(context, MainActivity.class);
webViewIntent.putExtra("url", "http://MYaweSOMEapp.com/app/articles/" + articleId);
webViewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(webViewIntent);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}