Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未接收4.4版本之前的KitKat设备上的推送功能_Android_Google Cloud Messaging - Fatal编程技术网

Android 未接收4.4版本之前的KitKat设备上的推送功能

Android 未接收4.4版本之前的KitKat设备上的推送功能,android,google-cloud-messaging,Android,Google Cloud Messaging,我正在使用GCM InstanceID类生成令牌。它在5.0或更高版本的设备上运行良好,但在4.4之前的KitKat设备上,我没有获得通过GCM的推送功能 清单 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.eliteappcreations.shouldigo">

我正在使用GCM InstanceID类生成令牌。它在5.0或更高版本的设备上运行良好,但在4.4之前的KitKat设备上,我没有获得通过GCM的推送功能

清单

<?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>

您可以在服务器端设置
delay\u while\u idle
标志为
false
,以便在棒棒糖下方使用GCM推送消息服务

在空闲时延迟

 @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();
    }
如果包含,则表示如果设备空闲,则不应立即发送消息。服务器将等待设备变为活动状态,然后仅发送每个密钥值的最后一条消息。可选。默认值为false,并且必须是JSON布尔值


有关更多信息,请参见

是否有任何错误?如果有,你能发布你的日志吗?@Umesh我不知道这是否只是你发布问题时的一个错误,但是清单中的TokenRegistrationEntertService声明没有正确关闭。没有必要调用
stopSelf()
OnHandleContent
中是
IntentService
而不仅仅是
服务
我没有收到kitkat设备下的推送。是的,我在棒棒糖下面说了,你在服务器上试过吗?