google cloud messaging not working in android 4.4

纵饮孤独 提交于 2019-12-11 04:08:21

问题


I have an andorid application that uses GCM (not the new google cloud messaging API)

the notification is working without any problems in all android vesion except 4.4 (nexus 5)

<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 
        <!-- Receive the actual message -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>  
            <category android:name="com.PushNotifications"/> 
        </intent-filter>  
        <!-- Receive the registration id -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>  
            <category android:name="com.PushNotifications"/> 
        </intent-filter> 
    </receiver> 

in android 4.4. GCMBroadcastReciver is not receiving the com.google.android.c2dm.intent.RECEIVE intent, only the com.google.android.c2dm.intent.REGISTRATION

I know that the old GCM is deprecated but I don't want use yet the Google Play Services and the new API, instead I want to understand why it's not working in 4.4

Thanks

full Android Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.PushNotifications" android:versionCode="1" android:versionName="1.0">  
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>  
<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false"/>  
<uses-permission android:name="android.permission.INTERNET"/>  
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  
<!-- Push permissions -->  
<permission android:name="com.PushNotifications.permission.C2D_MESSAGE" android:protectionLevel="signature"/>  
<uses-permission android:name="com.PushNotifications.permission.C2D_MESSAGE"/>  
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>  
<uses-permission android:name="android.permission.WAKE_LOCK"/>  
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>  
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>  
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  
<application android:label="@string/app_name" android:debuggable="true" android:icon="@drawable/icon"> 
    <activity android:name=".PushNotifications" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask"> 
        <intent-filter> 
            <action android:name="android.intent.action.MAIN"/>  
            <category android:name="android.intent.category.LAUNCHER"/> 
        </intent-filter>  
        <intent-filter> 
            <action android:name="com.PushNotifications.PushNotifications.NOTIFICATION"/>  
            <category android:name="android.intent.category.DEFAULT"/> 
        </intent-filter> 
    </activity>  
    <!-- Preference Activity  -->  
    <activity android:name="com.sample.common.WLPreferences" android:label="Sample"></activity>  
    <!-- Push service  -->  
    <!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver 
        It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->  
    <service android:name=".GCMIntentService"/>  
    <service android:name=".ForegroundService"/>  
    <!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->  
    <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 
        <!-- Receive the actual message -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>  
            <category android:name="com.PushNotifications"/> 
        </intent-filter>  
        <!-- Receive the registration id -->  
        <intent-filter> 
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>  
            <category android:name="com.PushNotifications"/> 
        </intent-filter> 
    </receiver> 
</application> 

来源:https://stackoverflow.com/questions/19952037/google-cloud-messaging-not-working-in-android-4-4

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