关于在android(https://parse.com/tutorials/android-push-notifications)上设置推送通知的parse.com教程。 ide是mac os maverick上的android studio 0.8.9。
错误 - >
Cannot use GCM for push because the app manifest is missing some required declarations
Also, please make sure that these services and broadcast receivers are declared as children of the <application> element
logcat输出 - &gt;
10-13 23:12:10.430 4942-4962/com.pixtas.sup 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.pixtas.sup.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.pixtas.sup.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.pixtas.sup" />
</intent-filter>
</receiver>
10-13 23:12:10.470 4942-4963/com.pixtas.sup D/dalvikvm﹕ GC_FOR_ALLOC freed 199K, 3% free 7918K/8156K, paused 34ms, total 34ms
10-13 23:12:10.600 4942-4942/com.pixtas.sup D/libEGL﹕ loaded /system/lib/egl/libEGL_tegra.so
10-13 23:12:10.630 4942-4942/com.pixtas.sup D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_tegra.so
10-13 23:12:10.640 4942-4942/com.pixtas.sup D/libEGL﹕ loaded /system/lib/egl/libGLESv2_tegra.so
10-13 23:12:10.670 4942-4942/com.pixtas.sup D/OpenGLRenderer﹕ Enabling debug mode 0
10-13 23:12:11.050 4942-4965/com.pixtas.sup D/dalvikvm﹕ GC_FOR_ALLOC freed 265K, 4% free 8165K/8468K, paused 23ms, total 23ms
10-13 23:12:11.420 4942-4975/com.pixtas.sup 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.pixtas.sup.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.pixtas.sup.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.pixtas.sup" />
</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>
AndroidManifest.xml - &gt;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pixtas.sup" >
// permissions required for parse.com
<uses-permission android:name="android.permission.INTERNET" />
<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.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.pixtas.sup.permission.C2D_MESSAGE" />
<uses-permission android:name="com.pixtas.sup.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
// register parse.com service and broadcast receivers
<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" />
<!--
IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name.
-->
<category android:name="com.pixtas.sup.pushnotifications" />
</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>
</application>
</manifest>
答案 0 :(得分:3)
代码已修复。认为有三个问题:
1)添加评论的语法错误。我使用的是java / objective-c语法:
// this is a comment
而不是xml方式
<!-- This is a comment -->
2)类别应该是<category android:name="com.pixtas.sup" />
(谢谢你疯狂)
3)需要为通知图标添加元数据。解析文档说这是可选的,但它似乎是强制性的,至少在某些情况下是这样。 (Android - Unable to start receiver com.parse.ParsePushBroadcastReceiver)
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_launcher" />
(谢谢Ahmad Raza)