android Gcm registrationID conflicts with 3rd party library like Parse - android

I have a simple project that use my gcm provider and also I want to implement parse library to send push for all user. But I have an issue about that situation. When I register the gcm with my GCMSenderID, I get the registrationID and then Parse register the gcm with its default GCMSenderID(1076345567071). Then I realized that the regID that get from my gcm provider has written the parse push table as deviceToken. For this reason I think, I cannot send push message to all devices with parse.
I use parse quickstart implementation also make some research from parse.com/docs/push_guide#top/Android.
How can I resolve this conflict?
Here is my implementation:
AndroidManifest.xml
<service android:name="com.parse.PushService" />
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/icon" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<receiver
android:name=".gcm.GcmBroadcastReceiver"
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="xxx.android" />
</intent-filter>
</receiver>
<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" />
<category android:name="xxxx.android" />
</intent-filter>
</receiver>
<receiver
android:name=".gcm.ParseReceiver"
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>
Application.java
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(this, ParseAPPLICATION_ID, ParseCLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
Parse uses its default sender id to request a GCM registration token: In particular, the SDK will automatically register your app for push at startup time using Parse's sender ID (1076345567071) and will store the resulting registration ID in the deviceToken field of the app's current ParseInstallation. (from parse.com/docs/push_guide#top/Android). So at startup 2 registrations for GCM tokens are requested, and my question is: how can I be sure which regToken Parse receives vs which regToken my GCM implementation/client receives? In theory they could get mixed up?

I fixed this issue with registering multiple senders by calling :
GoogleCloudMessaging.getInstance(this).register(YOUR_GCMSENDERID, PARSE_DEFAULT_GCM_SENDERID);
PARSE_DEFAULT_GCM_SENDERID = 1076345567071

Related

Disabling FirebaseMessagingService programmatically

I'm using Firebase for receiving push notifications. My problem is that i want to make an option for users available, where they can disable these Notifications.
<application android:label="MyApp" android:theme="#android:style/Theme.NoTitleBar" android:icon="#drawable/ico_myapp_application">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" 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="${applicationId}" />
</intent-filter>
</receiver>
<!-- END Manual Firebase Additions -->
</application>
Is there a way to prevent the app from register/creating the FirebaseMessagingService?
You could make options for users to Unsubscribe from your Firebase topic, they would stop getting the notifications. Unless if you are sending it directly to their ID.
FirebaseMessaging.getInstance().subscribeToTopic("news");
and then unsubscribe users
FirebaseMessaging.getInstance().unsubscribeFromTopic("news");

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

Android App force closes when using Push notification from Parse

I'm facing few problems since I started using Parse Push for android.
1. I'm unable to send notifications when the app is not running in the background.
2. The app force closes when it's not running in the background and I send a push notification.
3. The app force closes when I click on the push received.
Android Manifest
<service android:name="com.parse.PushService" />
<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>
<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="cn.loptest" />
</intent-filter>
</receiver>
Main Activity onCreate code
Parse.initialize(this, "********", "*******");
ParseInstallation.getCurrentInstallation().saveInBackground();
If I use PushService.setDefaultPushCallback with the above code I always get a "Connot Resolve Method"
TIA

GCM and Parse conflict

I have the below things in the AndroidManifest. I need to send push notifications from both my webservice and Parse. The problem is that if I run the app as is below, the pushes from my WS (webservice) will go through, but the ones from Parse won't.
If I comment out the GCM part, Parse will work.
I've also noticed that in the Parse table, when both are enabled, under the deviceToken column, Parse will add a |ID||1| prefix to the deviceToken. If I comment out the GCM part, Parse won't put that prefix to the deviceToken. I'm not sure if that matters ...
Any ideas what I am doing wrong? I need to support both functionalities, but it seems something conflicts with something else. Any ideas?
If you need more source code, let me know please ...
<!-- ================================= GCM ================================= -->
<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" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.moc.sif" />
</intent-filter>
</receiver>
<service
android:name=".pushnotif.gcm.GCMListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".pushnotif.gcm.GCMInstanceIdListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name=".pushnotif.gcm.GCMRegistrationIntentService"
android:exported="false">
</service>
<!-- ================================= PARSE ================================= -->
<service android:name="com.parse.PushService" />
<receiver
android:name=".pushnotif.parse.receivers.ParsePushReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<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>
<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.moc.sif" />
</intent-filter>
</receiver>
This should be fixed by Parse team. In my case unfortunetly the other 3rd library also getting token and there is no way to fix it. Parse also blocks "deviceToken" field so I cant event update it to correct one.
It seems I've fixed it.
The problem was that initializing Parse and afterwards I was calling this method:
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
String token = instanceID.getToken(getString(R.string.gcm_sender_id), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
which apparently made Parse override the deviceToken in the table. I was using the above token to send to my webservice. What I did to solve it was to comment out the above two lines and use the deviceToken generated by Parse instead. So both Parse and my webservice are receiving the same deviceToken obtained from the Parse library. And both work now ...

push notifications using parse.com not recieved on device

This is my code to send a push notification using parse.com in android.
ParseQuery installQuery = ParseInstallation.getQuery();
installQuery.whereEqualTo("userId", recieverObjectID);
ParsePush androidPush = new ParsePush();
androidPush.setMessage(currentUser.getUsername());
androidPush.setQuery(installQuery);
androidPush.sendInBackground();
In emulator I am able to send and receive push notifications, but I am not able to receive push notification on device. I manage to retrieve that in Installation table of parse when push-type is gcm for those devices or emulators push notifications are not sent. Guide me with solution.
if you are having a Parse account please go through the docs provided over there that will help you alot. you will have to make a class of parse application
public class ParseApplication extends Application{
public void onCreate() {
super.onCreate();
Parse.initialize(this,"app_id","Client_id");
ParseUser.enableAutomaticUser();
}
}
then in your launcher activity you have to intialise parse like this:
ParseInstallation currentInstall=ParseInstallation.getCurrentInstallation();
Have you made Parse Installation table as given in the docs.? you will have to register your device on Parse.
firstly do this:
ParsePush androidPush = new ParsePush();
androidPush.setMessage(currentUser.getUsername());
androidPush.setQuery(installQuery);
androidPush.saveInBackground();
check your manifest then u are Missing with some permissions can be Internet Permission or given below:
then in the application tag:
<service android:name="com.parse.PushService" />
<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" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<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>
OK. So then in Your parse Account go and click on Push You will surely get a push.

Categories

Resources