Reputation: 1659
I want to start google play through push notification using Parse.I am sending url through json using Parse Dashboard and getting it too. I tried a lot with broadcast receiver but get nowhere. So a little help or hint would be appreciable
Code
IntentFilter intentFilter = new IntentFilter("MyAction");
pushReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data") : "";
try {
JSONObject jsonObject = new JSONObject(message);
String url = jsonObject.getString("url");
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + url));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + url)));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
registerReceiver(pushReceiver, intentFilter);
Upvotes: 2
Views: 2200
Reputation: 813
What i found out from code is, if you don't do any magic by overriding ParsePushBroadcastReceiver's onPushOpen, you can add an uri and an action via web setting the type of the message from Text to JSON. For example this one we use to send users to Play with an information about an available update (if there version is very outdated):
{
"title": "<the title goes here>",
"alert": "<the message goes here>",
"uri": "https://play.google.com/store/apps/details?id=<package name>",
"action": "android.intent.action.VIEW"
}
There is no need for code since ParsePushBroadcastReceiver is taking care of that (using Parse version 1.9.4)
Upvotes: 1