Wie ich hier beziehe Android GCM messages repeated das Problem war ich installieren und installieren Sie die App viele Male, so dass es viele regId
hat. Ich habe viele Beiträge gefunden, um Canonical ID zu verwenden. Ich habe viele Beiträge gelesen, kann aber nicht wirklich wissen, wie ich es anwenden soll. Hier ist mein Code zu bekommen regId
:Android mit Canonical ID GCM
public String getRegId(){
int noOfAttemptsAllowed = 3; // Number of Retries allowed
int noOfAttempts = 0; // Number of tries done
boolean stopFetching = false; // Flag to denote if it has to be retried or not
String regId = "";
while (!stopFetching)
{
noOfAttempts ++;
try {
regId = gcm.register(PROJECT_NUMBER);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try
{
Thread.sleep(4000); // Set this timing based on trial.
try {
regId = gcm.register(PROJECT_NUMBER);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
/* try
{
// Get the registration ID
regId = gcm.register(PROJECT_NUMBER);
} catch (Exception e) {}*/
if (!regId.equals("") || noOfAttempts > noOfAttemptsAllowed)
{
// If registration ID obtained or No Of tries exceeded, stop fetching
stopFetching = true;
}
if (!regId.equals(""))
{
// If registration ID Obtained, save to shared preferences
SharedPrefrencesMethods.savePreferences(activity, "regid", regid);
}
}
return regId;
}
Okay dank dir jetzt verstehe ich, aber ich habe kleines Problem, das ich weiß nicht, wo Server empfangen Antwort auf welche Methode ich meine onHandleIntent intent Methode habe ich versucht, die Nachricht selbst nur zu bekommen? – Radwa
Hallo ich mange, um die Antwort vom Server zu erhalten und kanonische Ids zu erhalten, aber ich fand viele kanonische ID welche ich verwenden sollte das ist Teil der JSON Antwort {"Erfolg": 17, "Fehler": 15, "canonical_ids": 16 } – Radwa