简体   繁体   English

Android,如何检查应用程序的试用期是否到期?

[英]Android, How to check trial period of application is expired?

There are several packages in my application that user can select each one according to different prices. 我的应用程序中有几个软件包,用户可以根据不同的价格选择每个软件包。 In server side I store some information of client such as device Id, Android Id and etc. 在服务器端,我存储一些客户端信息,例如设备ID,Android ID等。

Based on the package that user choose, for example user has chosen 2 hours plan, server sends me Expire time and I store it in local database. 根据用户选择的包,例如用户选择了2个小时的计划,服务器会向我发送Expire时间并将其存储在本地数据库中。

The question is what is the best way to check that is trial period expired? 问题是检查试用期是否已过的最佳方法是什么? If user buy 2 hour plan at 12:00, therefore expire time will be at 14:00. 如果用户在12:00购买2小时计划,则到期时间将为14:00。 I store 14:00 in database and each time application lunched, I check the data base. 我将14:00存储在数据库中,每次应用程序进餐时,我都会检查数据库。 But the issue is if we assuming that user is using the application how to close application or prompt user that the plan has expired? 但是问题是,如果我们假设用户正在使用该应用程序,该如何关闭应用程序或提示用户该计划已过期? How do I understand if time of handset is changed by user? 我如何理解手机的时间是否被用户更改?

Is use of services best way? 使用服务是最好的方法吗? what things do you suggest? 你有什么建议?

============== Update: ============== 更新:

The point that I forgot to say is, because of some restrictions in our office I have access just to three activities that I'm designing and I can't ask other developers who are working on this project, check this and check that or use this variable. 我忘了要说的是,由于我们办公室的某些限制,我只能访问我正在设计的三个活动,并且不能问其他正在从事此项目的开发人员,请检查并检查或使用这个变量。 But because I'm working on main activity, this activity is the only activity that has access to database. 但是因为我正在从事主要活动,所以该活动是唯一有权访问数据库的活动。

You should maintain a flag in the SharedPreference and if the flag is set you could show an expiry message instead of your normal activity. 您应该在SharedPreference维护一个标志,如果设置了该标志,则可能会显示到期消息,而不是您的正常活动。 You could update the flag using AlarmManager once your period has expired. 您的期限到期后,可以使用AlarmManager更新该标志。

Here are few tutorials on AlarmManager and SharedPreferences . 这是有关AlarmManagerSharedPreferences的一些教程。

The easiest and best way to do this is the implement BackupSharedPreferences. 实现此目的最简单,最佳的方法是实施BackupSharedPreferences。

The preferences are preserved, even if the app is uninstalled and reinstalled. 即使卸载并重新安装了应用程序,首选项也会保留。

Simply save the install date as a preference and you are good to go. 只需将安装日期保存为首选项,就可以了。

Here's the theory: http://developer.android.com/reference/android/app/backup/SharedPreferencesBackupHelper.html 理论是这样的: http : //developer.android.com/reference/android/app/backup/SharedPreferencesBackupHelper.html

Here's the example: Android SharedPreferences Backup Not Working 这是示例: Android SharedPreferences备份不起作用

:) Pete :)皮特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM