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.
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();
}
You can set delay_while_idle
flag to false
in server side for working GCM push message service below Lollipop.
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. Optional. The default value is false, and must be a JSON boolean.
See the discussion for more
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.