所有其他方法中的第三种方法是最安全的(但并非万无一失),如果它需要更多资源,连接到internet,servidor web propio是创建一个唯一标识符远程检查器,它可以getDeviceId从设备获取并检查远程数据库是否存在,获取安装日期,如果不存在则添加新条目getDeviceId : fecha agregación。如果设备没有互联网,可以警告用户并终止应用程序。
每种方法的代码
未检查它们是否有效:
第一种方法使用示例SharedPreference
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
private final long ONE_DAY = 24 * 60 * 60 * 1000;
@Override
protected void onCreate(Bundle state){
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
String installDate = preferences.getString("InstallDate", null);
if(installDate == null) {
// First run, so save the current date
SharedPreferences.Editor editor = preferences.edit();
Date now = new Date();
String dateString = formatter.format(now);
editor.putString("InstallDate", dateString);
// Commit the edits!
editor.commit();
}
else {
// This is not the 1st run, check install date
Date before = (Date)formatter.parse(installDate);
Date now = new Date();
long diff = now.getTimeInMillis() - before.getTimeInMillis();
long days = diff / ONE_DAY;
if(days > 30) { // More than 30 days?
// Expired !!!
}
}
...
}
使用第二种方法的示例time-bomb
protected void onResume()
{
super.onResume();
Calendar expirationDate = Calendar.getInstance();
expirationDate.set(2016, 12, 31); //expirara final de año
Calendar t = Calendar.getInstance(); //obtener fecha actual
if (t.compareTo(expirationDate) == 1)
finish();
}
SO , SO , mobile-trial启发的答案
它可以实现的方式,从最简单的绕过到更复杂的。
第一种方法将安装日期保存到
base de datos
,fichero interno o externo de la app
或使用shared preferences
. 但是用户很可能会绕过试用时间限制:通过卸载并重新安装应用程序,如果文件使用外部位置,用户可能不会注意到残留物。第二种方法:使用固定期限
hard bomb-time
,即对于所有用户,该日期到期。绕过这个限制很容易,只需将系统时间更改为截止日期之前的日期,对于用户来说经常这样做并决定购买可能有点麻烦。所有其他方法中的第三种方法是最安全的(但并非万无一失),如果它需要更多资源,连接到
internet
,servidor web propio
是创建一个唯一标识符远程检查器,它可以getDeviceId
从设备获取并检查远程数据库是否存在,获取安装日期,如果不存在则添加新条目getDeviceId : fecha agregación
。如果设备没有互联网,可以警告用户并终止应用程序。每种方法的代码
未检查它们是否有效:
第一种方法使用示例
SharedPreference
使用第二种方法的示例
time-bomb
来自用户@Martin_christmman的第三种方法响应示例实现https://github.com/mobile-trial