I followed thus tutorial for parse notification on android https://parse.com/apps/quickstart#parse_push/android/native/existing
But I still can't receive the notifications in my App, this is my Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.walid.app_247_parse">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.walid.app_247_parse.C2D_MESSAGE" />
<uses-permission android:name="com.walid.app_247_parse.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserPhoneNumber" />
<activity android:name=".MainPage" />
<activity android:name=".ChatView" />
<activity android:name=".Connect_Main" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyAZmjxQ_QZRG-0m-oMNcl0zC0H_eOEB8Jw" />
<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="com.walid.app_247_parse" />
</intent-filter>
</receiver>
</application>
Also in my Launcher Activity I added these lines
Parse.initialize(this, getResources().getString(R.string.ParseAppID), getResources().getString(R.string.ParseClientID));
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("247APP", new SaveCallback() {
@Override
public void done(com.parse.ParseException e) {
Log.e("PARSE", "Successfully subscribed to Parse!");
}
});
And I can see the log of Successfully subscribed , and still whenever I send notification from parse.com nothing shown in my device. Please note that I am testing the App on Asus Zenfone 2 running android 5.
Change
Log.e("PARSE", "Successfully subscribed to Parse!");
to
if (e==null){
Log.e("Parse", "Success");
} else {
Log.e("PARSE", e.toString());
}
see what the error is or if it is actually successful for that portion.
Call Parse.initialize from the onCreate method of your Application class (instead of your Launcher Activity)
AndroidManifest.xml
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
MyApplication.java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(this, getResources().getString(R.string.ParseAppID), getResources().getString(R.string.ParseClientID));
// Subscribe to a channel
ParsePush.subscribeInBackground("twofourseven", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("PARSE", "Successfully subscribed to Parse channel");
} else {
Log.d("PARSE", "Failed to subscribe to Parse channel");
}
}
});
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
edit:
package name + ".permission.C2D_MESSAGE" (missing .permission)
<permission android:protectionLevel="signature" android:name="com.walid.app_247_parse.permission.C2D_MESSAGE" />
<uses-permission android:name="com.walid.app_247_parse.permission.C2D_MESSAGE" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.