2

I want to develop an android App with premiumn access which offer more possibilities to the user. The premium access is avaiblable for one month.After the one month, i want that the apps block the access. How can I manage it programmatically? Some precision: when the user get premium access, he can use the app without internet.So i want to put into the app a sort of Counter, which will count the number of day even if the apps is on,off or reboot.

I will be interrest if it is possible with j2me apps. Thank you

2 Answers2

1

You probably want to use google's in-app billing and sell them a subscription:

https://developer.android.com/google/play/billing/billing_subscriptions.html

NameSpace
  • 10,009
  • 3
  • 39
  • 40
1

If you don't want to use subscriptions as told in the other answer:
Use SharedPreferences. Save a bool for knowing if the user is premium. Also save a String with the current time when changing the bool because the user enabled premium. On every initialisation of your app check if its already time + 30 days and continue accordingly.

Something like this:

//enabling premium:
long time= System.currentTimeMillis();
String sTime = String.valueOf(time);
SharedPreferences premiumpref = new SharedPreferences();
premiumpref = getActivity().getSharedPreferences("premiumpref", Context.MODE_PRIVATE);
premiumpref.edit().putString("time",strTime).commit();


//next start:
long time= System.currentTimeMillis();
SharedPreferences premiumpref = new SharedPreferences();
premiumpref = getActivity().getSharedPreferences("premiumpref", Context.MODE_PRIVATE);
String startTime = premiumpref.getString("time","0");
Long lStartTime = Long.valueOf(startTime);
if((time-lStartTime) >= (86400000*30)) //thats the number of ms in a day
{
    //premium is over
}
Community
  • 1
  • 1
tritop
  • 1,655
  • 2
  • 18
  • 30
  • Please I don't understand the last phrase: "On every init check if its already time + 30 days." How can I manage the time exactly? – user3334222 Feb 22 '14 at 12:45
  • I liked you a thread, jsut click on time. You would have stored the current date when enabling premium. When you start up the App, you would get that date and check if that date - todays date is < 30 days. http://developer.android.com/reference/java/util/Calendar.html – tritop Feb 22 '14 at 12:52
  • Ok!!!Does the user can modify the date by changing parametter on it device or by rebooting? (excuse me for my english) – user3334222 Feb 22 '14 at 12:59
  • Unfortunatly my users can do this kind of things. What i can do is to oblige the user to check the access before our server. – user3334222 Feb 22 '14 at 13:51
  • In this case, our server will update (time-lStartTime). – user3334222 Feb 22 '14 at 13:52
  • But, does only rebooting can change the System.currentTimeMillis()? – user3334222 Feb 22 '14 at 13:54
  • 1. You could do the same getting the time from some timeserver on the internet, see http://stackoverflow.com/questions/13064750/how-to-get-current-time-from-internet-in-android 2. You could get the milliseconds from your server, that would involve some serverside work, but that shouldn't be much 3. If your user is logged in, you could do all the work on the server and just return if premium is valid – tritop Feb 22 '14 at 13:57
  • I didn't try how to manipulate the system.currenttimemillis, but I guess it is possible to manipulate it by just changing the device time, maybe even without rebooting. – tritop Feb 22 '14 at 13:58