我在数据库表中有一份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());
}
}
我有一个管理员应用程序,它充当第三方应用程序服务器,因为它向所有用户推送通知。我想使用以下方法从此管理员应用程序注销特定用户:
private void unRegister(String regId) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
try {
gcm.unregister();
}
catch (IOException e) {
System.out.println("Error Message: " + e.getMessage());
}
}
但是让我感到困惑的是,unregister() 方法不接受注册 ID 作为参数,这使得无法注销特定设备。是否有办法通过注册 ID 从 GCM 注销特定设备?