我有一个GCM注册用户列表及其在数据库表中的相应注册ID,我实际上想要在从表中删除用户时取消注册用户.我在Stackoverflow中找到了很多示例,但其中大多数都基于旧的GCMRegistrar API,现在已弃用.我正在使用GoogleCloudMessaging API并通过以下方法注册用户:
private void registerUser(){
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
String regId = "";
try {
regId = gcm.register(getString(R.string.project_number));
Log.i("registrationId", regId);
}
catch (IOException e) {
Log.i("Registration Error", e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个管理员应用程序,它充当第三方应用程序服务器,因为它将通知推送给所有用户.我想通过以下方法从此管理员应用中取消注册特定用户:
private void unRegister(String regId) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
try {
gcm.unregister();
}
catch (IOException e) {
System.out.println("Error Message: " + e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
但令我困惑的是,unregister()方法没有将注册ID作为参数,这使得无法注销特定设备.有没有办法通过注册ID从GCM取消注册特定设备?
android push-notification google-cloud-messaging google-play-services