无法接收来自 parse.com 的推送通知
Posted
技术标签:
【中文标题】无法接收来自 parse.com 的推送通知【英文标题】:Cannot receive push notification from parse.com 【发布时间】:2015-02-25 19:56:19 【问题描述】:我已经实现了 parse.com 在他们的教程中的内容,当我从 parse 仪表板发送推送时,它显示成功但发送的推送次数为 0。但是,每当我想发送推送时,它会显示接收者 1,这意味着它识别我的设备。我做了这个链接中所说的,但它不起作用: I can't receive push notifications in app from Parse 我很困惑为什么我在这里没有收到任何通知是我的应用程序类代码:
Parse.initialize(this, "xxxxx", "xxxxx");
ParseInstallation.getCurrentInstallation().saveInBackground();
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
ParsePush.subscribeInBackground("", new SaveCallback()
@Override
public void done(ParseException e)
if (e == null)
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
else
Log.e("com.parse.push", "failed to subscribe for push", e);
);
这是我的清单许可:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<permission android:name="com.myapp.main.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.main.permission.C2D_MESSAGE" />
这是与解析推送相关的清单的其余部分:
<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="com.myapp.main" />
</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>
<!-- replace @drawable/push_icon with your push icon identifier -->
<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/applogo"/>
编辑:这是日志:
02-25 13:52:53.681 4636-4653/com.myapp.main E/com.parse.ManifestInfo﹕ Cannot use GCM for push because the app manifest is missing some required declarations. Please make sure that these permissions are declared as children of the root <manifest> element:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission android:name="com.myapp.main.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.main.permission.C2D_MESSAGE" />
Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
<service android:name="com.parse.PushService" />
<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.myapp.main" />
</intent-filter>
</receiver>
02-25 13:57:13.004 5598-5598/com.myapp.main E/com.parse.PushService﹕ Tried to use push, but this app is not configured for push due to: Push is not configured for this app because the app manifest is missing required declarations. Please add the following declarations to your app manifest to support either GCM or PPNS for push (or both). To enable GCM support, please make sure that these permissions are declared as children of the root <manifest> element:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.myapp.main.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.main.permission.C2D_MESSAGE" />
Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
<service android:name="com.parse.PushService" />
<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.myapp.main" />
</intent-filter>
</receiver>
To enable PPNS support, please make sure that these permissions are declared as children of the root <manifest> element:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
<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>
02-25 14:12:25.534 10046-10046/com.myapp.main E/com.parse.push﹕ successfully subscribed to the broadcast channel.
【问题讨论】:
可以贴出错误日志吗? @Koh 我添加了日志 【参考方案1】:android:name="com.myapp.main.permission.permission.C2D_MESSAGE"
您可以将其更改为名称中只有一个“权限”吗?
【讨论】:
【参考方案2】:我将清单更改为:
<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>
<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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.vitrin.main" />
</intent-filter>
</receiver>
我仍然得到那个错误 + :
02-25 15:44:33.042 32710-32710/com.myapp.main E/com.parse.PushService﹕ PushService somehow started even though this device doesn't support push.
02-25 15:44:33.042 32710-32710/com.myapp.main E/com.parse.PushService﹕ Started push service even though no push service is enabled: Intent act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=com.myapp.main cmp=com.myapp.main/com.parse.PushService (has extras)
02-25 15:45:10.508 32710-32710/com.myapp.main E/com.parse.PushService﹕ Started push service even though no push service is enabled: Intent act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=com.myapp.main cmp=com.myapp.main/com.parse.PushService (has extras)
但由于某种原因它正在工作!
【讨论】:
以上是关于无法接收来自 parse.com 的推送通知的主要内容,如果未能解决你的问题,请参考以下文章
Parse.com 在 Xamarin 中推送 Android
从 parse.com 控制台接收推送时显示警报对话框而不是通知
android 使用 parse.com api 通过推送通知实现聊天