我正在实施 Android 应用程序以使用 Aerogear 和 OpenShift 发送和接收推送通知。我在注销设备时遇到问题,如果我打开应用程序并注册它可以工作的设备,我可以发送通知并且一切正常,如果我尝试注销设备也可以正常工作,我的问题是当我关闭应用程序并且我的设备已注册,如果我重新启动应用程序并且我想取消注册设备,则会收到此错误:
“服务器返回错误代码 404”
07-11 21:07:32.436 21158-21245/? D/GCM: GcmService start Intent { act=com.google.android.c2dm.intent.UNREGISTER pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmService (有附加功能) } com .google.android.c2dm.intent.UNREGISTER 07-11 21:07:32.606 20520-20520/? D / wpa_supplicant:RX ctrl_iface - hexdump(len = 11):53 49 47 4e 41 4c 5f 50 4f 4c 4c 07-11 21:07:32.606 20520-20520 /?D/wpa_supplicant﹕wlan0: 控制接口命令'SIGNAL_POLL' 07-11 21:07:32.606 20520-20520/? D/wpa_supplicant:nl80211:调查数据丢失!
这是我的实际代码
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
RegistrarManager.config(PUSH_REGISTER_NAME, AeroGearGCMPushConfiguration.class)
.setPushServerURI(new URI(UNIFIED_PUSH_URL))
.setSenderIds(GCM_SENDER_ID)
.setVariantID(VARIANT_ID)
.setSecret(SECRET)
.setAlias(ALIAS)
.setDeviceToken(ALIAS)
.asRegistrar();
PushRegistrar registrar = RegistrarManager.getRegistrar(PUSH_REGISTER_NAME);
registrar.register(getActivity().getApplicationContext(), new Callback<Void>() {
@Override
public void onSuccess(Void ignore) {
Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Exception exception) {
Toast.makeText(getActivity(), exception.getMessage(), Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
btnUnregister = (Button)mInflatedView.findViewById(R.id.btnUnregister);
btnUnregister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
RegistrarManager.config(PUSH_REGISTER_NAME, AeroGearGCMPushConfiguration.class)
.setPushServerURI(new URI(UNIFIED_PUSH_URL))
.setSenderIds(GCM_SENDER_ID)
.setVariantID(VARIANT_ID)
.setSecret(SECRET)
.setAlias(ALIAS)
.setDeviceToken(ALIAS)
.asRegistrar();
PushRegistrar registrar = RegistrarManager.getRegistrar(PUSH_REGISTER_NAME);
registrar.unregister(getActivity().getApplicationContext(), new Callback<Void>() {
@Override
public void onSuccess(Void ignore) {
Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Exception exception) {
Toast.makeText(getActivity(), exception.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}catch(Exception e){
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
有什么建议可以解决这个问题吗?