我想计算使用设备的所有缓存内存的总和.为此,我收到编译时间错误:
I want to calculate the sum of all the cache memory utilizing the device. For this I am getting a compiled time error:
IPackageStatsObserver cannot be resolved to a type
我在代码中已经两次提到这个错误:
I have mentioned this error 2 times in the code:
public long totalCacheSize(){
totalSize=0;
PackageManager packageManager = getApplicationContext().getPackageManager();
/* List<PackageInfo> packs = packageManager
.getInstalledPackages(PackageManager.GET_ACTIVITIES);*/
// PackageManager.GET_META_DATA
List<PackageInfo> packs = packageManager
.getInstalledPackages(PackageManager.GET_META_DATA);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
Method getPackageSizeInfo;
try {
getPackageSizeInfo = packageManager.getClass()
.getMethod("getPackageSizeInfo",
String.class, Class.forName("android.content.pm.IPackageStatsObserver"));
getPackageSizeInfo.invoke(packageManager, p.packageName,
new IPackageStatsObserver.Stub() { //error
public void onGetStatsCompleted(
PackageStats pStats, boolean succeeded)
throws RemoteException {
totalSize = totalSize + pStats.cacheSize;
Log.d("size", totalSize+"");
Toast.makeText(getApplicationContext(), "size"+totalSize, Toast.LENGTH_SHORT).show();
}
}
);
} catch (Exception e) {
try {
getPackageSizeInfo = packageManager.getClass()
.getMethod("getPackageSizeInfo",
String.class, Class.forName("android.content.pm.IPackageStatsObserver"));
getPackageSizeInfo.invoke(packageManager, p.packageName,
new IPackageStatsObserver.Stub() { //error
public void onGetStatsCompleted(
PackageStats pStats, boolean succeeded)
throws RemoteException {
totalSize = totalSize + pStats.cacheSize;
Log.d("size", totalSize+"");
Toast.makeText(getApplicationContext(), "size"+totalSize, Toast.LENGTH_SHORT).show();
}
}
);
} catch (Exception ee) {
Log.d("eeeeeeeeeee", "error");
ee.printStackTrace();
}
}
}
Log.d("return size", totalSize+"");
Toast.makeText(getApplicationContext(), "return size"+totalSize, Toast.LENGTH_SHORT).show();
return totalSize;
}
IPackageStatsObserver 在 android SDK 中不可用.可能使用 Class.forName() 加载 Stub 类,找到默认构造函数并调用它以获取 Stub 的新实例.但是我应该编码它,我对此一无所知!?
IPackageStatsObserver is not available in android SDK. Perhaps loading the Stub class using Class.forName(), finding the default constructor and invoke it to get a new instance of a Stub. But what should I code it, I do not know anything about it!?
求救!!
要解决您的问题,请按以下步骤操作:
To resolve your issue follow these steps:
Android Studio
aidl文件夹新建>包android.content.pm 并按 OKandroid.content.pm包内的aidl文件aidl folder New > Packageandroid.content.pm and press OKandroid.content.pm packageEclipse
src文件夹新建>包android.content.pmandroid.content.pm包内的aidl文件totalCacheSize 的类,然后 Source > Organize Importssrc folder New > Packageandroid.content.pmandroid.content.pm packagetotalCacheSize is then Source > Organize Imports这篇关于IPackageStatsObserver 无法解析为类型(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么在 Eclipse 的 SDK 中选择 Android API 而不是 Why would you choose Android API over Google APIs in the SDK on Eclipse?(为什么在 Eclipse 的 SDK 中选择 Android API 而不是 Google API?)
Couchbase 存储桶身份验证错误Couchbase Bucket authentication error(Couchbase 存储桶身份验证错误)
admob 6.2.1 空指针异常admob 6.2.1 nullpointer exception(admob 6.2.1 空指针异常)
如何在 IntelliJ IDEA 中设置 SDK?How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中设置 SDK?)
eclipse 无法检测到我的手机进行试运行My phone cannot be detected in eclipse to test run(eclipse 无法检测到我的手机进行试运行)
android SDK 中缺少 platform-toolsaapt.exe 目录platform-toolsaapt.exe directory missing in android SDK(android SDK 中缺少 platform-toolsaapt.exe 目录)