Android- App Does Not Receive Push Notifications From Parse Platform
I am using from parse platform but I can't receive any notification on my device android. Here is my manifest:
Solution 1:
Try this,
Add below code on Manifest file,
<meta-dataandroid:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" /><serviceandroid:name="com.parse.fcm.MyFirebaseMessagingService"><intent-filter><actionandroid:name="com.google.firebase.MESSAGING_EVENT" /></intent-filter></service><serviceandroid:name="com.parse.fcm.MyFirebaseInstanceIDService"><intent-filter><actionandroid:name="com.google.firebase.INSTANCE_ID_EVENT" /></intent-filter></service>
MyFirebaseMessagingService.java file
publicclassMyFirebaseMessagingServiceextendsFirebaseMessagingService {
publicstaticStringFCMTAG = "FCM Message";
publicstaticStringFCMSTATE = "FCMSTATE";
JSONObject jsonObject;
publicMyFirebaseMessagingService() {
super();
}
@OverridepublicvoidonMessageSent(String s) {
Log.v("Fcm", "MyFirebaseMessagingService :: onMessageSent " + s);
super.onMessageSent(s);
}
@OverridepublicvoidonMessageReceived(RemoteMessage remoteMessage) {
try {
if (remoteMessage != null && remoteMessage.getNotification() != null) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification.getTitle() != null && notification.getBody() != null) {
String title = notification.getTitle();
String message = notification.getBody();
Log.d("FCM", "Title: " + title + " , Message: " + message);
showStatusBarNotification(title, message);
}
}
} catch (Exception e) {
Log.d("FCM", "Error : " + e.getMessage());
e.printStackTrace();
}
}
privatevoidshowStatusBarNotification(String title, String sendMessage) {
//Code to show Push notification on Toolbar
}
}
MyFirebaseInstanceIDService.java file
publicclassMyFirebaseInstanceIDServiceextendsFirebaseInstanceIdService {
privatestaticfinalStringTAG="Fcm";
Context context;
String token;
publicMyFirebaseInstanceIDService() {
}
publicMyFirebaseInstanceIDService(Context context) {
this.context = context;
onTokenRefresh();
}
@OverridepublicvoidonTokenRefresh() {
FirebaseApp.initializeApp(context);
StringrefreshedToken= FirebaseInstanceId.getInstance().getToken();
Log.v(TAG, "MyFirebaseInstanceIDService: Refreshed token: " + refreshedToken);
}
public String getToken(){
return token;
}
}
Now You need to init MyFirebaseInstanceIDService on your onCreate
function of Activity page to generate the push token,
newMyFirebaseInstanceIDService(ShopLoginActivity.this);
Solution 2:
Remove android:exported="false"
from below service.
<serviceandroid:name="com.parse.fcm.ParseFirebaseMessagingService"android:exported="false"><intent-filter><actionandroid:name="com.google.firebase.MESSAGING_EVENT" /></intent-filter></service>
Might be from Firebase configuration setup.
Maybe you should go through the tutorial again. https://docs.parseplatform.org/tutorials/android-push-notifications/ To verify that you doing everything fine. As your code is clean, I can't figure out what is went wrong
Post a Comment for "Android- App Does Not Receive Push Notifications From Parse Platform"