我正在使用Android结算API V3查询来自Play商店的购买信息。我想知道是否可以清除本地缓存。
V3为计费API添加了本地缓存功能,以减少网络流量。我有一个更新服务,每天运行,更新我的元数据,因为我显示我的应用程序中的成本我希望刷新本地缓存并触发更新,以防我更新价格,以确保显示正确的价格。
文档说:
由于Google Play客户端现在可以在设备上本地缓存应用内结算信息,因此您可以使用版本3 API更频繁地查询此信息,例如通过getPurchases调用。与以前版本的API不同,许多版本3 API调用将通过缓存查找而不是通过与Google Play的网络连接进行服务,这大大加快了API的响应时间。
答案 0 :(得分:0)
试试这个:
添加此Application
课程:
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();
}
}
然后,从任何Activity
:
MyApplication.getInstance().clearApplicationData();
参考:
How to Clear User Data in your Android Application programmatically
感谢。
答案 1 :(得分:0)
不幸的是,Google Play客户端正在应用缓存,并且没有公开API来清除缓存。
我不明白你为什么要清除缓存呢? Google Play客户端会收到任何更改通知,因此会相应地使其缓存无效。假设返回的调用是正确的。
答案 2 :(得分:0)
您必须知道,一次购买一次android in app购买一次仅允许一个用户使用一次。您再次想要它时,您必须在Play控制台中提出请求或创建新产品。有关更多信息,请访问此链接。
https://developer.android.com/google/play/billing/billing_onetime