开源软件名称(OpenSource Name):MagicMicky/FreemiumLibrary开源软件地址(OpenSource Url):https://github.com/MagicMicky/FreemiumLibrary开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):FreemiumLibaryThis library hasn't been updated for a while and shouldn't be used as such. Feel free to fork it and update it :) The Android Freemium Library is a library that aims to help you put up a freemium model within your android application What is a Freemium Business Model?What I mean by Freemium Business Model is to propose users to use features from your apps for free, but will have to pay to use advanced features. They can also be shown ads when they are not premium - it's up to you. How does this library helps?This library implements and simplifies multiple functionalities that would be useful to you. It implements the in-app billing v3 used to charge user via the Google Play Store. It also implements the AdMob library that can be used to show ads to the user when he is not premium. Prepare your applicationFirst of all, you will need to create your application's project in the Play Store developer console, and create a "managed" in-app product (See Yourapp > In app products > Add new product). You will also need to note the License key of your application which is listed in the "Services & APIs" in the Developer Console. You might also want to note your application's ad-unit key (Monetize > YourApp > Ad Unit ID) You will also need to import the library to your application. In Eclipse, just import the project as an Android Library project. If you are using Android Studio and gradle, the easiest way to add the FreemiumLibrary to your project is to add the following dependency to your build.gradle:
Your App's ManifestYou also need to tweak a little your App's AndroidManifest.xml to add the library's permissions and activity. At the top level of your manifest, simply add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.vending.BILLING" /> How to use the library?To use the library you need to create an instance of a PremiumManager. It's advised to do so in the public PremiumManager(Activity activity, String premiumPackageId,String appPublicKey, String adId, Set<String> testDevices) { The PremiumManager constructor will take a few arguments:
To catch the return intent of the in-app payment, you will also need to implement the onActivityResult of your application and call the @Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(!(mPremiumManager != null && mPremiumManager.handleResult(requestCode, resultCode, intent))) {
Log.v(TAG, "Activity result not handled by PremiumManager");
//Handle your own results...
}
} Finally, you'll have to clean the PremiumManager in your activity's onDestroy call. protected void onDestroy() {
super.onDestroy();
if(mPremiumManager != null)
mPremiumManager.clean();
} Once your premium manager and your activity are set up, you will be able to select the features you want to use. Showing Ads when the user is not premiumTo show ads for a non-premium user, you just need to set it up via the PremiumManager's public void doAdsForNonPremium(int adsViewGroupRes, boolean upgradeLinkOnFailure, Integer adsReplacementLayoutRes) throws PremiumModeException The method doAdsForNonPremium will take as arguments:
The ad generated by AdMob is an This method will throw some exception when the Showing an upgrade button in your layout (i.e. in the drawer)To show an upgrade button on your application, you just need to call the method public void doUpgradeButtonForNonPremium(int upgradeButtonViewGroupRes, int upgradeButtonLayoutReference) throws PremiumModeException This method takes the following arguments
It throws Exception when the Showing an upgrade button in the MenuYou can also show an upgrade button in the menu. It will be available on pre and post honeycomb menu style.
You just need to call @Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(this.mPremiumManager!=null)
this.mPremiumManager.doMenuButtonForNonPremium(menu, getString(R.string.action_premium));
return super.onPrepareOptionsMenu(menu);
} This method will require the following arguments:
More advanced use.You also have access to other methods that could be useful in other cases.
Feel free to check the javadoc if you require more information. Featured projects.The library is currently used in my HabitRPG application. You can find it on the Google Play Store Developped by
License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论