简体   繁体   English

不接受4.4之前版本的KitKat设备的推送

[英]Not Receiving push on pre-4.4 KitKat device

I am using GCM InstanceID Class to generate the token.it is working fine on 5.0 or above device but on pre-4.4 KitKat device i am not getting the push through gcm. 我正在使用GCM InstanceID类生成令牌。它在5.0或更高版本的设备上运行良好,但是在4.4之前的KitKat设备上我无法通过gcm推送。

manifest 表现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eliteappcreations.shouldigo">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <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" />
    <!--
 The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


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


    <application
        android:name=".ShouldIGoApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".activity.SplashScreenActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activity.LoginActivity"
            android:label="@string/title_activity_login"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar" />

        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/google_maps_key" />
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/debug_facebook_app_id" />

        <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.eliteappcreations.shouldigo" />
            </intent-filter>
        </receiver>

        <service
            android:name=".service.gcmservice.GcmNotificationListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service
            android:name=".service.gcmservice.NotificationInstanceIDListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>
        <service
            android:name=".service.gcmservice.TokenRegistrationIntentService"
            android:enabled="true" />
    </application>

</manifest>

Service 服务

 @Override
    protected void onHandleIntent(Intent intent) {

        Log.i(TAG, "service started");

        InstanceID instanceID = InstanceID.getInstance(TokenRegistrationIntentService.this);
        try {
            String token = instanceID.getToken(getString(R.string.gcm_sender_id),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE);
            Log.i(TAG, token);

            if (token != null) {
                sendRegistrationTokenToServer(token);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        stopSelf();
    }

click here for documentation 单击此处获取文档

You can set delay_while_idle flag to false in server side for working GCM push message service below Lollipop. 您可以在服务器端将delay_while_idle标志设置为false ,以使Lollipop下的GCM推送消息服务正常工作。

delay_while_idle delay_while_idle

If included, indicates that the message should not be sent immediately if the device is idle. 如果包含该消息,则表明如果设备空闲,则不应立即发送该消息。 The server will wait for the device to become active, and then only the last message for each collapse_key value will be sent. 服务器将等待设备变为活动状态,然后将仅发送每个collapse_key值的最后一条消息。 Optional. 可选的。 The default value is false, and must be a JSON boolean. 默认值为false,并且必须为JSON布尔值。

See the discussion for more 查看更多讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM