如何知道是否清除了应用程序数据或卸载了应用程序? [英] How to know if application data is cleared or application is uninstalled?
问题描述
我正在开发基于 Login-Logout
机制以及 REST API
集成的应用程序.
I am developing application in which is based on Login-Logout
mechanism along with REST API
integration.
要发出 REST API
请求,需要 TOKEN
.应用程序正在将此 TOKEN
和其他用户详细信息保存到 SharedPreferences
.
For making REST API
request TOKEN
is required. Application is saving this TOKEN
and other user details to SharedPreferences
.
当用户登录的应用程序保存了所有必需的数据,并且在注销时,所有数据从 SharedPreferences
中删除,并且 TOKEN
条目从应用程序服务器中删除
When User logged in application saves all required data and at logout time all data is removed from SharedPreferences
and TOKEN
entry is deleted from application server
应用程序还向 GCM服务器
注册,用于向用户发送推送通知.对于该应用程序,将设备注册ID发送到应用程序服务器.
Application also register with GCM server
for sending push notification to user. For that application sends Device Register Id to application server.
但是,如果用户清除应用程序数据或卸载,则应用程序将打开登录屏幕并再次向应用程序服务器和GCM服务器注册,因此旧条目保留在应用程序服务器中,而新条目将添加到服务器中.
But if User clears application data or uninstall then application will open login screen and register again with application server and GCM server so old entry remains in application server and new entry is added to server.
因此,如果服务器向应用程序发送推送通知,则设备中会收到两个推送通知.
So if server send push notification to application then two push notification receives in device.
是否有任何方法可以通过程序检测是否清除了应用程序数据或卸载了应用程序?
Is there any way to detect programatically if application data is cleared or application is uninstalled?
任何帮助将不胜感激.
推荐答案
最后,我提出了以下解决方案.
Finally i came up with following solution.
我已经使用 Instance ID API
实现了 GCM 3.0
,以便使用 Application
和 GCM
向应用程序发送推送通知服务器,而不是旧的 GoogleCloudMessaging.register(SENDER_ID);
I have implemented GCM 3.0
with Instance ID API
for sending push notification to application using Application
and GCM
server instead of old GoogleCloudMessaging.register(SENDER_ID);
因此,当应用程序服务器尝试向设备发送推送通知时,服务器会收到旧设备ID的 "error":"NotRegistered"
响应,因此基于该服务器的设备将被删除没用的条目.
So when Application server try to send push notification to device then server gets "error":"NotRegistered"
response for old device id so based on that server will remove useless entry.
在GCM 2.0中,服务器有时会收到 错误":未注册"
响应,即使已安装应用程序,但在 GCM 3.0
中它也可以正常运行
In GCM 2.0 server gets "error":"NotRegistered"
response sometimes even if application is installed but in GCM 3.0
it works perfectly.
这篇关于如何知道是否清除了应用程序数据或卸载了应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!