是否有可能为应用程序一段时间后自行卸载? [英] Is it possible for an application to uninstall itself after a period of time?

查看:148
本文介绍了是否有可能为应用程序一段时间后自行卸载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算给我的应用程序客户端作为一个试验,我希望为它一段时间后会自动卸载。我的应用程序并不需要互联网连接。可以这样做?

I am planning to give my app to a client as a trial, and I wish for it to be automatically uninstalled after some time. My app does not need an internet connection. Can this be done?

谢谢!

推荐答案

首先,卸载应用程序会自动是不是好办法。尝试禁用所有功能。

First of all, uninstall app automatically is not good way. Try to disable all features.

一般情况下,你需要下面的算法:

Generally, you need the following algorithm:

1)在开始您的应用程序(例如,在第一个活动)获得共享preferences(的 http://developer.android.com/reference/android/content/Shared$p$pferences.html ),并检查与重点第一次启动的日期(例如firstStartDate )。此外,读取键lastStartDate。

1) On starting your app (for example in first activity) get SharedPreferences (http://developer.android.com/reference/android/content/SharedPreferences.html) and check key with date of first start (for example "firstStartDate"). Also, reads key "lastStartDate".

2)如果keyfirstStartDate不存在 - 这是你的应用程序的第一次首发,得到当前的日期和它写成两个键的值,不是继续应用程序的正常工作。

2) If key "firstStartDate" doesn't exist - it's first start of your app, get current date and write it as value of both keys, than continue normal work of app.

3)如果keyfirstStartDate的存在 - 获取当前的日期和检查你的审判没有过期(claculate第一天开始和当前日期算)。此外,检查当前日期是更或lastStartDate(改变对设备的保护,从日期)等于日期。如果当前日期小于lastStartDate - 这是黑客的日期和用户移动时间。在这种情况下,你可以完成试验(见第5点)。

3) If key "firstStartDate" exists - get current date and check that your trial is not expired (claculate days count between first start and current date). Also, check that current date is more or equal date in "lastStartDate" (protection from date changing on device). If current date is less than "lastStartDate" - it's date hack and user moved time. In this case you can finish trial (see point 5).

4)如果试验没有过期 - OK,继续正常的工作和写入当前日期为lastStartDate。

4) If trial is not expired - OK, continue normal work and write current date into "lastStartDate".

5)如果过期 - 展现给用户对话框(的http://开发商。 android.com/guide/topics/ui/dialogs.html )关于点击对话框按钮与参数撤销= FALSE和关闭活动过期的试用。

5) If expired - show to user dialog (http://developer.android.com/guide/topics/ui/dialogs.html) about expired trial with parameter cancellable=false and close activity on clicking dialog button.

我认为这将更好的不仅仅是卸载应用程序。

I think this will much better than just uninstall application.

这篇关于是否有可能为应用程序一段时间后自行卸载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆