I am working on integrate GCM to the android app, my working flow is first whenever the user enter the app, it check whether the share pref. has the gcm id, if not , then reg and save to share pref.
The problem is, it seems the id is duplicate after I install the app again. For example, if I install three times, then the app will receive three times of the message.
As I am using Amazon SNS service , the GCM id is store in their database, how can I handle the case of user re-install the app to prevent register again?
Thanks
if (gs.settings.getString("endpoint_arn", "").equals("")) {
gcm = GoogleCloudMessaging.getInstance(ctx);
asnsc = new AmazonSNSClient(new BasicAWSCredentials(Constant.id,Constant.secret));
asnsc.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1));
asnsc.setEndpoint("sns.ap-southeast-1.amazonaws.com");
new AsyncTask() {
@Override
protected Object doInBackground(final Object... params) {
try {
CreatePlatformEndpointRequest per = new CreatePlatformEndpointRequest();
per.setToken(gcm.register(Constant.projectID));
per.setPlatformApplicationArn(Constant.platformARN);
CreatePlatformEndpointResult result = asnsc.createPlatformEndpoint(per);
String arn = result.getEndpointArn();
gs.editor.putString("endpoint_arn", arn).commit();
}
}
You have to check for these 3 steps in order to set up everything working: