Handling android app uninstallation with Amazon SNS

We have done SNS setup for sending push notifications for our Android app. The step by step process is as follows:

  • Whenever the app comes up, it generates GCM registration ID by making a register call. The code snippet is below:

    private String registerOnGCM(){ try { GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext()); String token = gcm.register(Globals.GCM_TOKEN); return token; } catch (IOException e) { Log.e(TAG, "failed to complete token refresh process"); } return null; }

    where Globals.GCM_TOKEN is an the app ID obtained while doing the FCM registration for the app.

  • App makes a call to our backend server and pass this registration ID.

  • Backend server checks if this registration ID is new or not. If new, then it creates a new SNS endpoint using this registration ID and then subscribe the new endpoint to the Topic created for the user. And it persist all this data in our database for future reference.

  • When sending a push notification to all the devices for the user, we simply broadcast the message to the topic created for that user and the message is sent to all the devices owned by the user. This works just fine involving the case of multiple devices with our app installed on all of them. The problem arises on uninstallation and reinstallation.

    After reinstallation, the GCM registration call returns a separate registration ID and sends it to the backend. The backend detects it as a new device and register it for SNS and the user ends up with multiple SNS endpoints even though the device is the same. When pushing a notification to the topic for this user, the same device receives two push notifications. Probably because the older endpoint is still alive, it should have been disabled.

    So, my question: How to ensure that in the mentioned test case, only one push notification is sent to the android device.


    So here is the solution I found for my problem.

    In case of re-installation, the registration Id was changing and the same registration Id later gets used to detect if the device has already been registered for SNS pushes. But there is one more entity which is unique to the device and does not changes in case of re-installations, ie Device ID.

    I altered the backend call to our server and added one more parameter to it, the device Id. This Id now gets used for detecting already existing SNS registrations. In case, Id is already existing and the registration Id is new, then I will delete the old endpoint along with its subscription to the topic for that user and then carry on with the rest of the registration process. This will keep the data on SNS as well as our own data clean.

    链接地址: http://www.djcxy.com/p/32252.html

    上一篇: Lambda函数通过SNS接收空的S3事件对象

    下一篇: 使用Amazon SNS处理android应用程序卸载