error setting up push notification using parse.com and android studio

只谈情不闲聊 提交于 2020-01-20 08:43:44

问题


following the parse.com tutorial for setting up push notification on android (https://parse.com/tutorials/android-push-notifications). ide is android studio 0.8.9 on mac os maverick.

errors ->

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 output ->

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 ->

<?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>

回答1:


code fixed. think there were three issues:

1) wrong syntax for adding comments. i was using the java/objective-c syntax:

// this is a comment

instead of xml way

<!-- This is a comment --> 

2) category should have been <category android:name="com.pixtas.sup" /> (thank you berserk)

3) needed to add meta-data for notification icon. parse doc say this is optional, but it appears to be mandatory, at least in some cases. (Android - Unable to start receiver com.parse.ParsePushBroadcastReceiver)

<meta-data
            android:name="com.parse.push.notification_icon"
            android:resource="@drawable/ic_launcher" />

(thank you Ahmad Raza)



来源:https://stackoverflow.com/questions/26355187/error-setting-up-push-notification-using-parse-com-and-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!