Android Mixpanel push notification with sound - android

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

Related

Firebase Notification broke server notifications

I have made the switch from GCM to FCM in my android app. But I have not touched the server portion of the code since supposedly I don’t have to. But now, when server sends a notification, my device is no longer seeing it. So did I misunderstand the following?
https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints
Updating these endpoints is not strictly required, as Google will
continue to support the existing GCM endpoints.
MANIFEST
<!-- for notifications -->
<!--<uses-permission android:name="android.permission.WAKE_LOCK"/>-->
<!--<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>-->
<!--<uses-permission android:name="com.business.myapp.android.permission.C2D_MESSAGE"/>-->
…
<application …>
…
<!-- START GCM SECTION -->
<!--<receiver-->
<!--android:name="com.google.android.gms.gcm.GcmReceiver"-->
<!--android:exported="true"-->
<!--android:permission="com.google.android.c2dm.permission.SEND">-->
<!--<intent-filter>-->
<!--<action android:name="com.google.android.c2dm.intent.RECEIVE"/>-->
<!--<category android:name="com.business.myapp"/>-->
<!--</intent-filter>-->
<!--</receiver>-->
<service
android:name=".data.service.notification.BusinessGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".data.service.notification.BusinessInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service
android:name=".data.service.notification.RegistrationIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<!-- END GCM SECTION -->
Note that when I send notification from the Firebase Console it comes through: if the app is in the foreground, it goes through onMessageReceived; otherwise, I just get a notification in status bar. Basically I follow the instructions on the link provided.
Here is onTokenRefresh
#Override
public void onTokenRefresh() {
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);//intent service to send token to my server
}
Do you change your json-service.json of on root /app of on application ?

Overriding push notification in BroadcastReceiver (PushBots)?

migrating from Parse I got stuck by not being able to override PushBots notification creation code like I used to do with getNotification function in ParsePushBroadcastReceiver. My project needs multiline and separate push notifications, but PushBots default behavior is to show single line and group notifications by application.
I tried canceling notification in the onReceive function of BroadcastReceiver (PBConstants.EVENT_MSG_RECEIVE event), so I could create & display my own push, but I don't know notification ID and CancelAll() didn't work (also would be a bad idea).
Pushbots.sharedInstance() does have a setNotificationBuilder function, which accepts PBGenerate object, but I have no idea how to construct it properly and if this actually would help my case.
Couldn't find any documentation & get a response from support yet, so asking here if maybe someone knows a solution or a way to workaround this issue.
Here's how receivers are defined in AndroidManifest.xml
<receiver
android:name="com.pushbots.google.gcm.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.my.app" />
</intent-filter>
</receiver>
<receiver android:name="com.my.app.MyPushReceiver" />
<service android:name="com.pushbots.push.GCMIntentService" />
Thank you in advance!

mixpanel push notification is sending 2 notifications

I am using mixpanel in my app and I am getting 2 notifications from mixpanel. I am already using gcm on my device for chat. How can I receive both mixpanel and my notifications. BTW I generate GCM reg_id via code.
Manifest file:
<receiver
android:name=".gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter android:priority="100">
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name=“com.example.Mainactivity.gcm" />
</intent-filter>
</receiver>
<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="com.example.Mainactivity.gcm" />
</intent-filter>
</receiver>
<service android:name=".gcm.GcmIntentService" />
I have added :
mixpanel.registerSuperProperties(props);
mixpanel.identify(id);
mixpanel.getPeople().identify(id);
mixpanel.getPeople().setPushRegistrationId(reg_id);
mixpanel.getPeople().initPushHandling(SENDER_ID);
in my GcmBroadcastReceiver I have added:
if (intent.getExtras().containsKey("mp_message")) {
String mp_message=intent.getExtras().getString("mp_message");
}
Check if you have added same device token in multiple people's property (comma separated)
As you are saying you implemented GCM before and you integrated Mixpanel afterwards. In that case you should remove the Mixpanel GCMReceiver tag as mentioned in the official documentation:
If you are handling registration and receiving notifications yourself,
you shouldn't include the Mixpanel GCMReceiver tag in your
AndroidManifest.xml file.
https://mixpanel.com/help/reference/android-push-notifications

Parse.com: Get Pushnotification Message on onPushOpen

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.

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.

Categories

Resources