I Want To Receive Push Notification Using Parse And Display It In An Activity. How Can I Get The Values From Parse Notification?
I tried this to save a push ParseQuery parseq=ParseInstallation.getQuery(); parseq.whereEqualTo('role', 'manager'); ParseObject p=ParseInstallation.getCurrentInstallation(); Par
Solution 1:
This little code can get all the text from a push, you can do your things with it:
@OverridepublicvoidonReceive(Context context, Intent intent) {
super.onReceive(context, intent);
JSONObject json = null;
try {
json = newJSONObject(intent.getExtras().getString("com.parse.Data"));
String text = json.getString("alert").toString();
} catch (JSONException e) {
e.printStackTrace();
}
}
just put it inside your onReceive() method of your ParsePushBroadcastReceiver.
I hope this help you.
Solution 2:
You need to do following for getting the value from push notification.
Add the ParsePushReciever in your main package.
import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.BitmapFactory; import android.support.v4.app.NotificationCompat; import com.parse.ParsePushBroadcastReceiver; publicclassParsePushRecieverextendsParsePushBroadcastReceiver { @OverridepublicvoidonPushOpen(Context context, Intent intent) { AppLog.e("Push", "Clicked"); Intenti=newIntent(context, MainActivity.class); i.putExtras(intent.getExtras()); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } @OverridepublicvoidonReceive(Context context, Intent intent) { Log.d("Push Notification",intent.getExtras().get(ParsePushBroadcastReceiver.KEY_PUSH_DATA).toString()); NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builderbuilder=newNotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.launcher); Intent newIntent=newIntent(context,MainActivity.class); newIntent.putExtra(context.getString(R.string.navigation_from_notification),true); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pi=PendingIntent.getActivity(context, 0, newIntent, 0); builder.setContentIntent(pi); builder.setContentText("Push Notification"); Log.d("Notification", strMsg); nm.notify(1, builder.build()); } }
Add the reciever in your manifest file:
<receiverandroid:name=".ParsePushReciever"android:exported="false" ><intent-filter><actionandroid:name="com.parse.push.intent.RECEIVE" /><actionandroid:name="com.parse.push.intent.DELETE" /><actionandroid:name="com.parse.push.intent.OPEN" /></intent-filter></receiver><meta-dataandroid:name="com.parse.push.notification_icon"android:resource="@drawable/launcher" />
Check for notification in your MainActivity:
if(getIntent()!=null) { if (getIntent().getExtras()!=null && getIntent().getExtras().getBoolean(getString(R.string.navigation_from_notification))) { //get data from intent and display it in your activity. } }
Post a Comment for "I Want To Receive Push Notification Using Parse And Display It In An Activity. How Can I Get The Values From Parse Notification?"