Parse.com: Get Pushnotification Message on onPushOpen - android

In my android application I am using the push notifications supplied by Parse.com. I have successfully got this working, however my application has multiple push notifications and different activities should be loaded depending on which push notification has been pressed. I expected to be able to get the message for the push notification from the intent parameter of the onPushOpen, but it seems to be empty? . Does anyone know how I could get the message in the onPushOpen method?.
For some context, I have added my current custom PushReceiver code below.
public class PushReceiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, Splash.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Thanks.

Make sure you've upgraded to Parse-1.8.2.
Then you'll also need to do two more things.
Add information into your AndroidManifest.xml (within )
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com...ADD_PACKAGE_INFO_HERE..." />
</intent-filter>
</receiver>
<receiver android:name="com..ADD_PACKAGE_INFO_HERE....PushReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
Add this to AndroidManifest.xml outside the tags
Within the cloud code on Parse.com, set the uri of the broadcast to "com....ADD_PACKAGE_INFO_HERE...PushReceiver"
NB: #1 & #2 should be provided for you in the debug trace when you run your android app.
Hope this helps. I spent hours trying to get this to work and the key for me was updating to 1.8.2.
EDIT:
You should also look at overriding onReceive as well as onPushOpen...that actually gets called on a notification. Good luck.

Related

Android Mixpanel push notification with sound

I've developed an app which uses push notifications with Mixpanel. They are working well, including deep linking.
The problem is that my customer want them to sound once received but they don't play any sound.
After reading the docs I know that for iOS is as easy as adding a field in the custom data, but with Android there is no sound field to customize this.
If I'm not wrong the only solution is to extend the Mixpanel broadcast receiver, so I changed my AndroidManifest from this:
<receiver android:name="com.mixpanel.android.mpmetrics.GCMReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package.name" />
</intent-filter>
</receiver>
to this:
<receiver android:name=".auxiliary.LocalNotificationBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package.name" />
</intent-filter>
</receiver>
And I've added this class .auxiliary.LocalNotificationBroadcastReceiver:
import com.mixpanel.android.mpmetrics.GCMReceiver;
public class LocalNotificationBroadcastReceiver extends GCMReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
super.onReceive(context, intent);
}
}
This way push notifications sent from Mixpanel are still received correctly, but I don't know how to add sound to this notification.
Any help would be very appreciated!
Fork the MixPanel library and customize the notification builder.
Note the following:
MixPanel uses MPConfig to get notification defaults
MixPanel doesn't use NotificationCompat so there are several builder methods (might be because they don't include the support lib).
This is where they build the notification:
https://github.com/mixpanel/mixpanel-android/blob/master/src/main/java/com/mixpanel/android/mpmetrics/GCMReceiver.java#L376

BroadcastReceiever on separate process

I have a BroadcastReceiver which is working, but when I go into recent and swipe the app to get rid of it, the receiver stops working.
So i wanted to add this to the manifest i nhopes to prevent the receiver from dying
<receiver
android:name=".CounterReceiver"
android:enabled="false"
android:process=":counterreceiver">
<intent-filter>
<action android:name="com.example.johnbravado.zionwork.MESSAGE_PROCESSED" />
</intent-filter>
</receiver>
Send the receiver to a different process. Now, however, my receiver does not work at all. If I remove the android:process="" line, it goes back to working as expected.
Is this normal behavior or do i need to sendBroadcasta special way for the receiver to hear it since it is ona separate process?
Edit:
Here is the sending system. the sender is coming from a service
#Override
public void onMessageReceived(final MessageEvent messageEvent) {
nodeId = messageEvent.getSourceNodeId();
String incomingPath = messageEvent.getPath();
int incomingReq = Integer.parseInt(new String(messageEvent.getData()));
if(incomingPath.equalsIgnoreCase(MyConstants.MSG_COUNTER_REQ_PATH)) {
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(MyConstants.BROADCAST_ACTION_RESP);
//broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra(MyConstants.BROADCAST_DATA_REQ, incomingReq);
sendBroadcast(broadcastIntent);
}else if(incomingPath.equalsIgnoreCase(MyConstants.MSG_DEFAULT_PATH)){
}
}
The sending service manifest
<service
android:name=".MyWearableListenerService"
android:enabled="false">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:scheme="wear" />
</intent-filter>
</service>
I know i have enabled=false that is not issue as i set it to true via package manager.

Let user enable/disable Push Notifications in Parse

I'm developing an Android app that uses Push Notifications from Parse. On my settings menu I want to have an option to enable/disable push notifications but I can't find a way to do it using the parse library. All the ways I found online seem to be using methods that are now deprecated.
I'm not using channels, I just call Parse.initialize when starting the app.
Do you know how I can achieve this? To clarify I just need to know how to make the device ignore incoming notifications.
Regards
Ok, I've worked out a solution. What I had to do was implement my own Receiver that replaces Parse's.
public class MyCustomReceiver extends ParsePushBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context,intent);
}
}
Then in AndroidManifest.xml replace this :
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
with this (put your package name) :
<receiver
android:name="your.package.name.MyCustomReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.example.UPDATE_STATUS" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
Then rewrite your onReceive as you please, for instance, what I did was:
#Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!sharedPrefs.contains("NOTIF") || sharedPrefs.getBoolean("NOTIF", false))
super.onReceive(context,intent);
}
The variable NOTIF in SharedPreferences says if that user wants to receive notifications or not.

How can I get data or title from receiving notifications?

I create simple "ParseStarterProject" as default of parse.com project. It works. I send notification from one device to other device successfully via setchannel method.
But the problem is I do not use receiver class(I do not know how can I use that) so when a notification comes I need to get its message ? it is possible? or if I use set data can I get its data ?
I use this code to send message:
ParsePush push = new ParsePush();
String yourMessage = "Selam from LG G2";//I want to get this message from other device?
push.setChannel("device2");
push.setMessage(yourMessage);
//push.setData("exampledata"); if I use this can I get this data from other device?
push.sendInBackground();
my manifest file:
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
thanks in advance
Create a class that extends BroadcastReceiver, here we call it MyCustomReceiver. Declare the usage of this receiver in your manifest:
<receiver android:name="com.example.MyCustomReceiver" android:exported="false">
<intent-filter>
<action android:name="com.example.UPDATE_STATUS" />
</intent-filter>
</receiver>
I'm not sure what you mean by you have problems with "MyCustomReceiver class on the main activity", in your comment to #kingspeech's answer.
In the worst case, you can create your own Receiver which extends the ParseBroadcastReceiver (and reference the extended class in the manifest). Then it should work by default, but you'll be able to hook into onReceive(Context, Intent)
As Parse tutorial directs, you ca use JSONObject to set data and you can put whatever you want.
Then when you receive Push notification you can have a access to read the previously prepared JSONObject. Please look at the Android tutorial https://parse.com/docs/push_guide#options/Android.
Hope this helps,
Regards.

Android: receiving intent sent by system ACTION_PACKAGE_RESTARTED

I am new to android. I get completely stuck in using ACTION_PACKAGE_RESTARTED in my application
I have removed pacakge from my emulator, also added using adb install but get nothing. Start an app. close that one and again start that app. nothing seems work for me. There is no log in logcat.
Is there anything that i'm missing? Please help
public class RestartReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action= intent.getAction();
Log.i("D", "Inside receiver");
}
And here is the manifest file
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".ReceiverTest">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.ACTION_PACKAGE_RESTARTED" />
</intent-filter>
</receiver>
</application>
the value specified in the intent filter is incorrect..actual value is
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
and this broadcast can be received for other packages only. Restarted application/package doesn't receive this broadcast.
You should add a data specification to the intent-filter:
<data android:scheme="package" />

Categories

Resources