Question

I am using the Android Billing API V3 for querying purchase information from the play store. I am wondering if it is possible to clear the local cache.

V3 added the local caching feature for the billing API to cut down on network traffic. I have an update service which is run daily which updates my metadata and since I display the costs in my application I wish to flush the local cache and trigger an update in case I have updated prices to ensure the correct price is shown.

Documentation says:

Because the Google Play client now caches In-app Billing information locally on the device, you can use the Version 3 API to query for this information more frequently, for example through a getPurchases call. Unlike with previous versions of the API, many Version 3 API calls will be serviced through cache lookups instead of through a network connection to Google Play, which significantly speeds up the API's response time.

Was it helpful?

Solution 2

Unfortunately not, the Google Play client is app doing the caching, and there is not an API exposed to clear the cache.

I don't see why you want to clear the cache though? The Google Play client is notified of any changes, so would invalidate it's cache accordingly. Just assume the calls returned are correct.

OTHER TIPS

You must know that the android in app purchase one time purchases are allow only one time in the lifetime for one user. you want it again you have to make a request or create a new product in play console. for more go to this link.

https://developer.android.com/google/play/billing/billing_onetime

Try this :

Add this Application class :

package com.hrupin.cleaner;

import java.io.File;

import android.app.Application;
import android.util.Log;

public class MyApplication extends Application {
    private static MyApplication instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    public static MyApplication getInstance() {
        return instance;
    }

    public void clearApplicationData() {
        File cache = getCacheDir();
        File appDir = new File(cache.getParent());
        if (appDir.exists()) {
            String[] children = appDir.list();
            for (String s : children) {
                if (!s.equals("lib")) {
                    deleteDir(new File(appDir, s));
                    Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
                }
            }
        }
    }

    public static boolean deleteDir(File dir) {
        if (dir != null && dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }

        return dir.delete();
    }
}

Then, Make this call from any Activity:

MyApplication.getInstance().clearApplicationData();

Reference :

How to Clear User Data in your Android Application programmatically

Thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top