Amazon-In-App-Entitlement

Additional

Language
Java
Version
1.0.0 (Sep 21, 2018)
Created
Apr 18, 2018
Updated
Jun 10, 2019 (Retired)
Owner
Adnan Naeem (adnaanaeem)
Contributor
Adnan Naeem (adnaanaeem)
1
Activity
Badge
Generate
Download
Source code

Amazon-In-App-Entitlement

Amazon In App Entitlement for inapp purchases

Add it in your root build.gradle at the end of repositories:

allprojects {
   repositories {
    ...
    maven { url 'https://jitpack.io' }
   }
}

Step #2. Add the dependency See Latest Release

dependencies {
         implementation 'com.github.Adnan865:Amazon-In-App-Entitlement:1.0.0'
 }

Declare varibales of InApp Library and Broadcast Receiver

private BroadcastReceiver br;
AmazonInApp amazonInApp = new AmazonInApp();

Initilize Amazon Inapp veraibales

 amazonInApp.setProductID(getResources().getString(R.string.product_ID));
 amazonInApp.onCreateAmazonInApp(_context);

Now add this methods in activity or fragment

 private void setupLibraryReceiver() {
        br = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent i) {
                if (amazonInApp.getPurchase(_context)) {
                    disableButoon();
                }
            }
        };
        _context.registerReceiver(br, new IntentFilter(amazonInApp.getBroadCastReceiver(_context)));
    }

Call this module in on create method.

 setupLibraryReceiver();

Implemnet overide methods

    @Override
    protected void onResume() {
        super.onResume();
        amazonInApp.onResumeAmazonInApp();
    }

    @Override
    protected void onStart() {
        super.onStart();
        amazonInApp.onStartAmazonInApp();
    }
    @Override
    protected void onPause() {
        super.onPause();
        amazonInApp.onPauseAmazonInApp();
    }

Add these also if you are working with fargments

 // Used for Fragment broadcast
    @Override
    public void onAttach(Context context)
    {
        super.onAttach(context);
        _context = context;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        _context.unregisterReceiver(br);
    }

Now just Call this method to purchase

 amazonInApp.purchase();

For SandBox Test Purchase Enviroment do below tasks

  • Downlaod Amzaon app store app from here and install it.
  • Downlaod Amazon App Tester app here or from amzaon app store and instal it also.
  • Get json file for test product key from app here and copy to phone memory.
  • All set now download the peoject and run the demo app for purchase demo.