在android上parsing通知不起作用

我想在Android上设置Parse推送通知一段时间了。 我跟着不同的教程,我试图从他们的networking平台发送通知,但似乎没有任何工作。 这是我到目前为止所尝试的。

这是我的应用程序类的onCreate方法

@Override public void onCreate() { super.onCreate(); Log.i("PushNotifications","PARSE initialize"); Parse.initialize(this, "******************************", "*****************************"); ParseInstallation.getCurrentInstallation().saveInBackground(); ParsePush.subscribeInBackground("", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.i("PushNotifications","com.parse.push" + " successfully subscribed to the broadcast channel."); } else { Log.i("PushNotifications","com.parse.push" + " failed to subscribe for push"); } } }); } 

这被称为成功,因为我得到的日志

成功订阅了广播频道。

这里还有一些我的清单文件的相关内容:

 <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <permission android:name="com.my.app.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.my.app.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".App" android:theme="@style/AppTheme"> <activity android:name=".activities.MainActivity" android:launchMode="standard" android:screenOrientation="sensorPortrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.parse.push.gcm_sender_id" android:value="id:123456789" /> <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/> <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.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> <!--com.parse.GcmBroadcastReceiver"--> <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.my.app" /> </intent-filter> </receiver> </application> 

当我尝试从Parse网站发送推送,没有任何反应。

由于这不起作用,我试图实现我自己的GcmBroadcastReceiver并在清单中更改它。

 <receiver android:name=".receivers.MyCustomReceiver" 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.my.app" /> </intent-filter> </receiver> 

 public class MyCustomReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i("PushNotifications","MyCustomReceiver"); } } 

没有成功。

然后我也尝试创build我自己的ParsePushBroadcastReceiver(通过inheritanceParsePushBroadcastReceiver)。

 <receiver android:name=".receivers.CustomParseReceiver" 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> 

 public class CustomParseReceiver extends ParsePushBroadcastReceiver { @Override protected Notification getNotification(Context context, Intent intent) { Log.i("PushNotifications","PARSE getNotification"); return null; } @Override protected void onPushOpen(Context context, Intent intent) { Log.i("PushNotifications","PARSE onPushOpen"); } @Override protected void onPushReceive(Context context, Intent intent) { Log.i("PushNotifications","PARSE onPushReceive"); } private JSONObject getDataFromIntent(Intent intent) { Log.i("PushNotifications","PARSE getDataFromIntent"); } } 

它也没有工作。

事情是..当我创build我自己的GCM BroadcastReceiver,并从我自己的服务器(用一些小的PHP脚本)发送通知,通知成功收到。

我真的不知道我的客户端parsing通知系统的实现有什么问题。

任何暗示问题可能来自哪里?

Solutions Collecting From Web of "在android上parsing通知不起作用"

我的2美分(希望这有助于):

我有一个类似的问题,我解决了( 这里解释),所以这可能是问题,如果不是,看看我的文件,一眼看来,他们似乎有一点点不同,你的,他们的工作,所以它值得一看:

清单部分:

  <!-- for parse pushes --> <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.MyStuff.stuff.utils.MyPushReceiver" android:exported="false" > <intent-filter> <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> <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.MyStuff.stuff" /> </intent-filter> </receiver> <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher" /> 

我实现了我自己的ParsePushBroadcastReceiver:

 public class MyPushReceiver extends ParsePushBroadcastReceiver { @Override protected void onPushOpen(Context context, Intent intent) { //bla bla... } @Override protected void onPushReceive(Context context, Intent intent) { // bla bla... } @Override protected Notification getNotification(Context context, Intent intent) { Notification notification = super.getNotification(context, intent); // do some stuff with it.. } } 

和我的应用程序类:

 public class MyApplication extends Application { private static final String CKey = "***********"; private static final String AId = "************"; @Override public void onCreate() { super.onCreate(); Parse.initialize(this, AId, CKey); //initialized some stuff.. ParsePush.subscribeInBackground("", new SaveCallback() { @Override public void done(ParseException e) { if (null == e) { ParseInstallation install = ParseInstallation.getCurrentInstallation(); String token = install.getString("deviceToken"); //do some stuff with it... } } }); ParseInstallation.getCurrentInstallation().saveInBackground(); //some more stuff } 

希望它能使你走上正确的道路!

第一:你是否启用了从你的项目设置推送通知设置

我面临同样的问题,最后我删除了我的项目,并在Parse中build立一个新的问题,然后解决问题而不做更多的事情! 为什么? 我不知道 …

不要忘了总是得到最新的Parse SDK,现在它的Parse-1.9.2.jar