2
我正在實現推送通知,但在調用getToken時收到TIMEOUT異常。GCM getToken()在某些設備上發送java.io.IOException:TIMEOUT
此問題僅在某些設備上發生,如SC-03D(4.0)。
這裏是我的IntentService我使用註冊標記:
public class RegistrationIntentService extends IntentService {
private static final String TAG = "GCM";
public static final String TOKEN_ID = "registration_id";
/**
* Constructor
*/
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
try {
// In the (unlikely) event that multiple refresh operations occur simultaneously, ensure that they are processed sequentially.
synchronized (TAG) {
// Initially this call goes out to the network to retrieve the token, subsequent calls are local.
InstanceID instanceID = InstanceID.getInstance(this);
String gcm_sender_id = getString(R.string.gcm_sender_id);
String token = instanceID.getToken(gcm_sender_id, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
String storageToken = PrefsHelper.getTokenId(this);
Log.d(TAG, "GCM Registration Token: " + token);
}
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
}
}
非常感謝@Ayaanp。我會嘗試與您的解決方案:) –
嗨@Ayaanp,超時錯誤仍然發生與您的解決方案。 –
你的意思是說你根本沒有收到註冊令牌?或者在一次或兩次嘗試後得到一個? – Ayaanp