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
Related
I have updated parse sdk which forces me to migrate from GCM to FCM. I have followed this link :
https://github.com/codepath/android_guides/wiki/Push-Notifications-Setup-for-Parse
I am able to receive push notification when app is running or is in background but not when app is killed.
Here is my AndroidManifest.xml :
<service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.parse.fcm.ParseFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:name=".receiver.CustomParsePushReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_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.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
CustomParsePushReceiver.java
public class CustomParsePushReceiver extends ParsePushBroadcastReceiver {
#Override
protected void onPushReceive(Context context, Intent intent) {
Log.e("ParsePushReceiver","Parse receiver received notification");
}
}
I have updated parse server, parse sdk, parse-fcm, firebase-core and firebase-messaging to latest version.
You need to have a separate receiver for com.parse.ParsePushBroadcastReceiver
Place your other actions (like Boot_Complete) on separate 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>
Some stock ROMs kill all the background processes when the app is killed. Hence the push service is killed and I was not able to receive push when app is killed. Some of those manufacturers are OnePlus, Lenovo, Xiomi, Oppo and Vivo. But when I tested in other devices such as HTC and Samsung it worked !!!
For more info read this blog : https://medium.freecodecamp.org/why-your-push-notifications-never-see-the-light-of-day-3fa297520793
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 ...
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.
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
I'm attempting to override the default behaviour of the receipt of push notifications from Parse.com's API on the android platform. As per various posts on SO, and in Parse's documentation - I've created the following class:
public class HHPBroadcastReceiver extends ParsePushBroadcastReceiver {
protected void onPushReceive(Context context,
Intent intent){
Log.d("DMM", "onPushReceive");
}
protected void onPushOpen(Context context, Intent intent) {
Log.d("DMM", "onPushOpen");
}
}
In my manifest, I'm also overriding the receiver as follows:
<!-- <receiver
android:name="com.parse.ParseBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
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.dreamr.hothalls.HHPBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
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>
Upon receipt of a push notification, my Receiver doesn't seem to get called - A notification appears in the notification area and clicking this carries out the default action. Nowhere in Logcat does my debug message appear.
I'm at my wit's end trying to work out what is most likely something incredibly simple I've overlooked.
Any advice or suggestions would be much appreciated,
Cheers,
Sean
You must register GCM broadcast receiver as well
<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="us.anyadir.admissiontable" />
</intent-filter>
</receiver>