我按照教程上的解析通知教程 https://parse.com/apps/quickstart#parse_push/android/native/existing
但我仍然无法在我的应用程序中收到通知,这是我的清单
<?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>
同样在我的启动器活动中,我添加了这些行
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!");
}
});
我可以看到成功订阅的日志,而且每当我从parse.com发送通知时,我的设备中都没有显示。 请注意,我正在测试运行android 5的Asus Zenfone 2上的应用程序。
答案 0 :(得分:0)
更改
Log.e("PARSE", "Successfully subscribed to Parse!");
到
if (e==null){
Log.e("Parse", "Success");
} else {
Log.e("PARSE", e.toString());
}
查看错误是什么,或者该部分实际上是否成功。
答案 1 :(得分:0)
从Application类的onCreate方法调用Parse.initialize(而不是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);
}
}
编辑:
包名+&#34; .permission.C2D_MESSAGE&#34; (遗失。许可)
<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" />