【问题标题】:Android GCM push notifications not working on devices with JellybeanAndroid GCM 推送通知不适用于带有 Jellybean 的设备
【发布时间】:2016-08-26 09:44:47
【问题描述】:

我在 Android Marshmallow、Lollipop 和 Kitkat 上测试了该应用,除了 Jellybean 4.2.2 的设备外,push 在所有这些设备上都能正常工作。

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.sample">
    <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" />
    <uses-permission android:name="com.test.sample.permission.C2D_MESSAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_TASKS" />

    <permission
        android:name="com.test.sample.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
<uses-permission android:name="com.test.sample.permission.C2D_MESSAGE"></uses-permission>
    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@drawable/sgrficon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppFullScreenTheme">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/gcmKey" />

        <activity
            android:name="com.test.sample.SplashActivity"
            android:noHistory="true"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.test.sample.LandingPage"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme" />
        <activity
            android:name="com.test.sample.WebfragmentActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.test.sample.LandingPage" />
        </activity>
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            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.test.sample" />
            </intent-filter>
        </receiver>

        <service android:name=".GcmPushService">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"></action>
            </intent-filter>
        </service>
        <service
            android:name=".GcmIntentService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>

        <activity
            android:name=".PdfFragmentActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme"></activity>
    </application>
</manifest>

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        applicationId "com.test.sample"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations {
        all*.exclude group: 'com.google.firebase', module: 'firebase-common'
    }
    configurations.all {
        resolutionStrategy {
            force 'com.android.support:design:24.1.1'
            force 'com.android.support:support-v4:24.1.1'
            force 'com.android.support:appcompat-v7:24.1.1'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.maps.android:android-maps-utils:0.4+'

    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.android.support:design:24.1.1'
    compile 'com.afollestad.material-dialogs:core:0.8.6.2'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:recyclerview-v7:24.1.1'
    compile 'com.google.android.gms:play-services:9.4.0'
}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

标签: android push-notification google-cloud-messaging android-4.2-jelly-bean


【解决方案1】:

如果我是你,我会在 GCM 上尝试 Google 的演示并与我的代码进行比较。

https://github.com/google/gcm/tree/master/samples/android/gcm-demo

它支持 Android 4.X (API-15)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    相关资源
    最近更新 更多