Is a Trial-like behavior possible in android apps

纵然是瞬间 提交于 2019-12-12 22:07:55

问题


I'm new to Android developement (I know very basic stuffs), and there is a chance that soon I'll be tasked with porting a WP7 app to Android (fortunately, I can use MonoDroid...).

Now that app has a trial functionality (see here), which for WP7 means that I can check whether the user bought it (so I can enable additional features inside the app) or downloaded the free edition. I do not want the trial to expire, I want a "free edition" of my app to be limited to certain features.

Is there anything similiar for Android? (And can it be done on MonoDroid?)

I've looked at Google Licensing Service, but I don't see how that helps me.


回答1:


I would go for two apps solution. One "real" application, which contains all the functionality. Second "key" application which only check licensing.

First application will check if the key application is installed. If the check is positive then display full content, enable all features. If the key application is missing the application behaves like free version.

It is also very important to check if the private key that signed both applications is the same. Without this check someone might create their own key application and unlock your functionality. To do so consider this snippet, which I took from this blog: http://www.yoki.org/2010/07/31/creating-a-freepaid-app-pair-for-the-android-market/

protected boolean isProInstalled(Context context) {
  // the packagename of the 'key' app
  String proPackage = "org.yoki.android.pkgname";

  // get the package manager
  final PackageManager pm = context.getPackageManager();
  // get a list of installed packages
  List<PackageInfo> list = 
         pm.getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS);

  // let's iterate through the list
  Iterator<PackageInfo> i = list.iterator();
  while(i.hasNext()) {
    PackageInfo p = i.next();
    // check if proPackage is in the list AND whether that package is signed
    //  with the same signature as THIS package
    if((p.packageName.equals(proPackage)) &&
       (pm.checkSignatures(context.getPackageName(), p.packageName) == PackageManager.SIGNATURE_MATCH))
      return true;
  }
  return false;
}

This approach gives you few advantages in flexibility:

  • separate paid areas. You can assign sets of features to different key applications. eg. app key1 unlocks additional game levels a1,a2,a3 and app key2 unlocks levels b1,b2
  • time licensing - instead of only checking the existence of key application. You can query it to check if the licence is still valid. That way you can achieve time licences.



回答2:


Probably the best way for you would be to use in-app purchases



来源:https://stackoverflow.com/questions/8725501/is-a-trial-like-behavior-possible-in-android-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!