how can we get device token for android for push notification?

ⅰ亾dé卋堺 提交于 2019-12-14 04:16:59

问题


i want to implement push notification in my application.i want to know,how we get the device token for push notification in android after enabling the google cloud messaging API.How can we get a device token for a particular device??


回答1:


try {
     InstanceID instanceID = InstanceID.getInstance(this);

     String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

            Log.i(TAG, "GCM Registration Token: " + token);

}catch (Exception e) {
            Log.d(TAG, "Failed to complete token refresh", e);
}


来源:https://stackoverflow.com/questions/33560598/how-can-we-get-device-token-for-android-for-push-notification

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