使用 Parse 推送通知错误

Posted

技术标签:

【中文标题】使用 Parse 推送通知错误【英文标题】:Push Notification Error using Parse 【发布时间】:2014-05-14 17:28:08 【问题描述】:

尝试使用 Parse 添加推送通知。调试告诉我在清单中添加缺失的声明,这些声明已经存在。我是否在清单中错误地放置了我的代码? (第一个使用 android SDK 的应用程序)我尽可能地遵循 Parse 示例代码,三次检查了教程,现在几乎没有想法了

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.megger.cablecalcplustwo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <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" />
    <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" />

    <!--
      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.megger.cablecalcplustwo.pushnotifications.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.megger.cablecalcplustwo.pushnotifications.permission.C2D_MESSAGE" />



    <application



        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.Black.NoTitleBar">
        <activity
            android:name="com.megger.cablecalcplustwo.CableCalcActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.megger.cablecalcplustwo.CcActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.CalculatorActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuideActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.CablesActivity" android:label="@string/app_name" android:theme="@style/AlphaActivity"/>
        <activity android:name="com.megger.cablecalcplustwo.ContactActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuideMultifunctionActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuidePatActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuideLoopActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuideInsulationActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuideElectriciansActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuideClampActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.GuidePageActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.WebViewActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.AboutActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.VideoViewActivity" android:label="@string/app_name" android:configChanges="orientation" />
        <activity android:name="com.megger.cablecalcplustwo.VideoActivity" android:label="@string/app_name" />
        <activity android:name="com.megger.cablecalcplustwo.CompetitionsAndEvents" android:label="@string/app_name" />

        <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.megger.cablecalcplustwo.pushnotifications" />
            </intent-filter>
        </receiver>




        <compatible-screens>

            <screen android:screenSize="small" android:screenDensity="ldpi" />
            <screen android:screenSize="small" android:screenDensity="mdpi" />
            <screen android:screenSize="small" android:screenDensity="hdpi" />
            <screen android:screenSize="small" android:screenDensity="xhdpi" />

            <screen android:screenSize="normal" android:screenDensity="ldpi" />
            <screen android:screenSize="normal" android:screenDensity="mdpi" />
            <screen android:screenSize="normal" android:screenDensity="hdpi" />
            <screen android:screenSize="normal" android:screenDensity="xhdpi" />

            <screen android:screenSize="large" android:screenDensity="ldpi" />
            <screen android:screenSize="large" android:screenDensity="mdpi" />
            <screen android:screenSize="large" android:screenDensity="hdpi" />
            <screen android:screenSize="large" android:screenDensity="xhdpi" />

            <screen android:screenSize="xlarge" android:screenDensity="ldpi" />
            <screen android:screenSize="xlarge" android:screenDensity="mdpi" />
            <screen android:screenSize="xlarge" android:screenDensity="hdpi" />
            <screen android:screenSize="xlarge" android:screenDensity="xhdpi" />



        </compatible-screens>


    </application>
</manifest>

Logcat

05-14 18:04:52.415  29036-29055/com.megger.cablecalcplustwo 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.megger.cablecalcplustwo.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.megger.cablecalcplustwo.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.megger.cablecalcplustwo" />
    </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>

【问题讨论】:

【参考方案1】:

您应该将所有显示com.megger.cablecalcplustwo.pushnotifications 的位置更改为com.megger.cablecalcplustwo,因为那是您应用的包名称。

【讨论】:

非常感谢,不能告诉你我为此争论了多久!

以上是关于使用 Parse 推送通知错误的主要内容,如果未能解决你的问题,请参考以下文章

解析推送通知错误

Swift 2 Parse 推送通知

尝试使用 Parse.com 获取推送通知无法在设备上运行

预期返回“布尔”parse.com 推送通知的函数中缺少返回

使用 Parse 的基于位置的推送通知

Parse:从应用发送推送通知