Это проблема с идентификатором GCM. Попробуйте использовать Thread.sleep и повторите попытку несколько раз, пока не будет получен идентификатор GCM.
int noOfAttemptsAllowed = 5; // Number of Retries allowed
int noOfAttempts = 0; // Number of tries done
bool stopFetching = false; // Flag to denote if it has to be retried or not
String regId = "";
while (!stopFetching)
{
noOfAttempts ++;
GCMRegistrar.register(getApplicationContext(), "XXXX_SOME_KEY_XXXX");
try
{
// Leave some time here for the register to be
// registered before going to the next line
Thread.sleep(2000); // Set this timing based on trial.
} catch (InterruptedException e) {
e.printStackTrace();
}
try
{
// Get the registration ID
regId = GCMRegistrar.getRegistrationId(LoginActivity.this);
} catch (Exception e) {}
if (!regId.isEmpty() || noOfAttempts > noOfAttemptsAllowed)
{
// If registration ID obtained or No Of tries exceeded, stop fetching
stopFetching = true;
}
if (!regId.isEmpty())
{
// If registration ID Obtained, save to shared preferences
saveRegIDToSharedPreferences();
}
}
Thread.sleep и noOfAttemptsAllowed можно играть вокруг с на основе вашего дизайна и других параметров. У нас было время сна 7000, так что вероятность регистрации при первой попытке выше. Однако, если это не удастся, следующая попытка будет потреблять еще 7000 мс. Это может заставить пользователей думать, что ваше приложение работает медленно. Итак, играйте разумно с этими двумя значениями.
Спасибо, я попробую это – LastElb