difference between deprecated gcm and new gcm which uses google play service

匆匆过客 提交于 2019-12-12 03:28:54

问题


Is deprecated gcm reliable to use now and when probably will be down?I mean gcm which has no depency on google play service(gcm.jar-GCMRegistar version). I tested latest gcm version and found out that the bulit apk is more than 2.0 mb size ,which is very bigger than old gcm.jar. Furthermore the old gcm does not need google play service and some older devices has not installed google play service,so the old gcm can run on more devices. Here is the gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.mygcm"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
   compile 'com.google.android.gms:play-services:8.4.0'
}

回答1:


When using the new gcm library you should include the individual dependency not the entire play-services library.

use:

compile 'com.google.android.gms:play-services-gcm:8.4.0'

instead of:

compile 'com.google.android.gms:play-services:8.4.0'

Same for other Play Services libraries eg: play-services-drive




回答2:


Although the old GCMRegistrar API will still be supported, you should definitely change to the new GCM API. The new InstanceId API has many advantages and improvements comparing to the old one and works very well (I tested it in production for months).

https://developers.google.com/instance-id/#key_features

Instance ID, Identity, and Authorization

Instance ID (IID) allows you to retrieve a unique identifier for every app instance, providing a mechanism to authenticate and authorize actions, even if your app does not have user registration and accounts. For example, this allows you to uniquely determine which app instance is sending a request from by including the Instance ID token. We’ve also made it easy to handle edge cases to ensure that you’ll have valid Instance ID tokens.

And here is the very interesting part from the server side:

https://developers.google.com/instance-id/reference/server#get_information_about_app_instances

About the library size and as @Arthur pointed out you should just use what you need from the Play Services library. Here you have the list of individual libraries you can refer from gradle instead the whole bundle.



来源:https://stackoverflow.com/questions/35919247/difference-between-deprecated-gcm-and-new-gcm-which-uses-google-play-service

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