簡體   English   中英

特定設備未收到Google Cloud Messaging通知

[英]Specific device not receiving Google Cloud Messaging notifications

我有一個應用程序,我正在實施Google Cloud Messaging通知,但在特定設備中,消息不會到達。 此設備具有使用GCM的最低要求(Android版本2.2,安裝了Play商店並記錄了Google帳戶) 在日志中,我看到設備正在接收注冊ID並發送到后台,我在其中注冊了設備列表。

我的問題是:我是否需要進行額外配置才能使設備接收這些通知?

這是清單

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

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />   
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission android:name="com.example.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

    <application
        android:name="TesteGCM"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >        

        <receiver
            android:name="br.com.testegcm.GcmBroadcastReceiver" 
            android:exported="true"
            android:enabled="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="br.com.testegcm" />
            </intent-filter>
        </receiver>

        <service android:name="br.com.testegcm.GcmIntentService" />

        <activity
            android:name="br.com.testegcm.Home"
            android:screenOrientation="portrait"
            android:label="@string/app_name"
            android:theme="@style/notitle" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity>
 </application>
</manifest>

改變這個:

<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

至 :

<permission android:name="br.com.testegcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="br.com.testegcm.permission.C2D_MESSAGE" />

添加相同的問題,我最終意識到我需要將清單中的廣播接收器包名稱從com.example.gcm更改為我的包名:

 <!-- Push notifcations-->
        <receiver
                android:name=".BroadcastRecivers.GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                <category android:name="com.example.gcm"/>
            </intent-filter>
        </receiver>

<!-- Push notifcations-->
        <receiver
                android:name=".BroadcastRecivers.GcmBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                <category android:name="MY PACKAGE NAME"/>
            </intent-filter>
        </receiver>

Android版本2.2外, 沒有 安裝Play商店應用程序且登錄的Google帳戶無需其他配置,現在只剩兩個案例

1) Either there is some ambiguity in your code. 
2) or may be it is a device specific issue.

我有同樣的問題。我的代碼可以在nexus4(Kitkat)上工作,但是無法從appln服務器(通過gcm服務器)給我一個通知。對於低於4.0.4的版本,你應該確保你有你的谷歌設備上的帳戶設置,以便gcm正常工作。 我的手機上有谷歌帳戶,但我犯的錯誤是我的銀河王牌中的帳戶和同步設置是“關閉”。當我打開它並運行我的代碼時,我收到了通知。

請檢查以下解決方案。 如果仍然無法工作,請告訴我。 在兩個不同的intent過濾器中添加RECEIVE和REGISTRATION Intent

<receiver
            android:name=“<.GCM BroadcastReceiver Name>“  // Name of your BroadcastReceiver, define in code.                                                                                                         
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>  
               <action android:name="com.google.android.c2dm.intent.RECEIVE" />
               <category android:name=“<Package Name>" />
            </intent-filter>
                 <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name=“<Package Name>" />
            </intent-filter>
        </receiver>
        <service android:name=“<.GCM IntentService Name>" />  // Name of your IntentService, define in code.
<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

如上所示,在兩個不同的意圖過濾器中添加RECEIVE和REGISTRATION Intent,否則它將不適用於某些設備(例如HTC)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM