本文整理汇总了Java中android.content.pm.IPackageStatsObserver类的典型用法代码示例。如果您正苦于以下问题:Java IPackageStatsObserver类的具体用法?Java IPackageStatsObserver怎么用?Java IPackageStatsObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPackageStatsObserver类属于android.content.pm包,在下文中一共展示了IPackageStatsObserver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override public void onCreate() {
try {
mGetPackageSizeInfoMethod = getPackageManager().getClass()
.getMethod(
"getPackageSizeInfo",
String.class,
IPackageStatsObserver.class);
mFreeStorageAndNotifyMethod = getPackageManager().getClass()
.getMethod(
"freeStorageAndNotify",
long.class,
IPackageDataObserver.class);
mDeleteApplicationCacheFiles = getPackageManager().getClass()
.getMethod(
"deleteApplicationCacheFiles",
String.class,
IPackageDataObserver.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
开发者ID:towavephone,项目名称:MemoryCleaner,代码行数:23,代码来源:CleanerService.java
示例2: doInBackground
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
mCallback.onBegin();
PackageManager pm = MyApplication.getInstance().getPackageManager();
List<ApplicationInfo> installedPackages = pm.getInstalledApplications(PackageManager.GET_GIDS);
IPackageStatsObserver.Stub observer = new PackageStatsObserver();
mScanCount = 0;
mTotalCount = installedPackages.size();
mSysCaches = new ArrayList<>();
mAppNames = new HashMap<>();
for (int i = 0; i < mTotalCount; i++) {
ApplicationInfo info = installedPackages.get(i);
mAppNames.put(info.packageName, pm.getApplicationLabel(info).toString());
getPackageInfo(info.packageName, observer);
}
return null;
}
开发者ID:mzlogin,项目名称:CleanExpert,代码行数:22,代码来源:SysCacheScanTask.java
示例3: setAppSize
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/**
* 根据包名获取应用程序的体积信息 注意: 这个方法是一个异步的方法 程序的体积要花一定时间才能获取到.
*
* @param packname
*/
private void setAppSize(final String packname) {
try {
Method method = PackageManager.class.getMethod("getPackageSizeInfo", new Class[] { String.class, IPackageStatsObserver.class });
method.invoke(getPackageManager(), new Object[] { packname, new IPackageStatsObserver.Stub() {
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException {
// 注意这个操作是一个异步的操作
long codesize = pStats.codeSize;
long datasize = pStats.dataSize;
Logger.i(TAG, packname);
CacheInfo info = maps.get(packname);
info.setDataSize(Formatter.formatFileSize(mApp, datasize));
info.setCodeSize(Formatter.formatFileSize(mApp, codesize));
maps.put(packname, info);
}
} });
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:bingoogolapple,项目名称:Graduation-Design,代码行数:26,代码来源:OptimizeActivity.java
示例4: doInBackground
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override
protected Boolean doInBackground(Void... params) {
mCallBack.onScanStart();
ArrayList<CacheInfo> caches = CacheLab.get(mAppContext).getCaches();
caches.clear();
mScanCount = 0;
mTotalCount = 0;
PackageManager pm = mAppContext.getPackageManager();
List<ApplicationInfo> installedPackages = pm.getInstalledApplications(PackageManager.GET_GIDS);
IPackageStatsObserver.Stub observer = new PackageSizeObserver();
mTotalCount = installedPackages.size();
for (int i = 0; i < mTotalCount; i++) {
ApplicationInfo appInfo = installedPackages.get(i);
// NOTICE!This call is not synchronize
getPackageInfo(appInfo.packageName, observer);
}
return true;
}
开发者ID:mzlogin,项目名称:AndroidPractices,代码行数:23,代码来源:CacheScanTask.java
示例5: doInBackground
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override
protected List<AppsListItem> doInBackground(Void... params) {
mCacheSize = 0;
final List<ApplicationInfo> packages = getPackageManager().getInstalledApplications(
PackageManager.GET_META_DATA);
publishProgress(0, packages.size());
final CountDownLatch countDownLatch = new CountDownLatch(packages.size());
final List<AppsListItem> apps = new ArrayList<>();
try {
for (ApplicationInfo pkg : packages) {
mGetPackageSizeInfoMethod.invoke(getPackageManager(), pkg.packageName,
new IPackageStatsObserver.Stub() {
@Override
public void onGetStatsCompleted(PackageStats pStats,
boolean succeeded)
throws RemoteException {
synchronized (apps) {
publishProgress(++mAppCount, packages.size());
mCacheSize += addPackage(apps, pStats, succeeded);
}
synchronized (countDownLatch) {
countDownLatch.countDown();
}
}
}
);
}
countDownLatch.await();
} catch (InvocationTargetException | InterruptedException | IllegalAccessException e) {
e.printStackTrace();
}
return new ArrayList<>(apps);
}
开发者ID:Frozen-Developers,项目名称:android-cache-cleaner,代码行数:44,代码来源:CleanerService.java
示例6: getCaches
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
private void getCaches(){
// scan
pm = getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(0);
int max = packages.size();
int current = 0;
sb.delete(0, sb.length());
sb.append("");
sb.append("本机一共安装了:" + max+"个应用");
tvShowCaches.setText(sb.toString());
for (PackageInfo pinfo : packages) {
String packageName = pinfo.packageName;
try {
Method getPackageSizeInfo = PackageManager.class
.getDeclaredMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);
getPackageSizeInfo.invoke(pm, packageName, new MyPackageStateObserver());
current++;
} catch (Exception e) {
current++;
e.printStackTrace();
}
}
//===到这里,数据准备完成
mHadler.postDelayed(new Runnable() {
@Override
public void run() {
btnClearAll.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(),"已读取全部缓存",Toast.LENGTH_SHORT).show();
sbCache.append(Formatter.formatFileSize(getApplicationContext(),cacheS)+"\n");
tvShowCaches.setText(sb.toString());
tvAppCache.setText(sbCache.toString());
sbCache.delete(0,sbCache.length());
}
}, 1000);
//ok,所有应用程序信息显示完成
}
开发者ID:stytooldex,项目名称:stynico,代码行数:40,代码来源:MainActivity.java
示例7: getPackageInfo
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
private void getPackageInfo(Context context, String pkg) {
PackageManager pm = context.getPackageManager();
try {
Method method_getPackageSizeInfo = pm.getClass().getMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);
method_getPackageSizeInfo.invoke(pm, pkg, new IPackageStatsObserver.Stub() {
@Override
public IBinder asBinder() {
log.d("asBinder");
return super.asBinder();
}
@Override
public void onGetStatsCompleted(PackageStats packageStats, boolean b) throws RemoteException {
final StringBuilder sb = new StringBuilder("onGetStatsCompleted\n");
sb.append("packageName:").append(packageStats.packageName).append("\n");
sb.append("cacheSize:").append(packageStats.cacheSize).append("\n");
sb.append("dataSize:").append(packageStats.dataSize).append("\n");
sb.append("externalDataSize:").append(packageStats.externalDataSize).append("\n");
log.i(sb.toString());
mHandler.post(new Runnable() {
@Override
public void run() {
mDataBinding.txtContent.setText(sb);
}
});
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:vipycm,项目名称:mao-android,代码行数:34,代码来源:PmFragment.java
示例8: getCacheSize
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/**
* 获取某个包名对应的应用程序的缓存大小
* @param
*/
public void getCacheSize(PackageInfo info) {
try {
Method method = PackageManager.class.getDeclaredMethod(
"getPackageSizeInfo",String.class,IPackageStatsObserver.class);
method.invoke(packageManager,info.packageName,new MyPackObserver(info));
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:sh2zqp,项目名称:MobilePhoneSafeProtector,代码行数:15,代码来源:CacheClearListActivity.java
示例9: onCreate
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override public void onCreate(Bundle savedInstanceState) {
//position = mContext.getArguments().getInt(ARG_POSITION);
try {
mGetPackageSizeInfoMethod = mContext.getPackageManager()
.getClass()
.getMethod("getPackageSizeInfo",
String.class,
IPackageStatsObserver.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
//mTaskScanApps = new TaskScanApps();
//mAppsView.initViews(mAppsListAdapter,mContext,);
}
开发者ID:towavephone,项目名称:MemoryCleaner,代码行数:15,代码来源:AppsPresenter.java
示例10: getAppSize
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/**
* get app size by package name
* @param context
* @param packageName package name
* @param listener it will be call when success to get size
*/
public static void getAppSize(Context context, String packageName, final AppSizeInfoListener listener) {
// check argument
if(null == listener) {
throw new NullPointerException("listener can't be null");
}
if(TextUtils.isEmpty(packageName)) {
throw new IllegalArgumentException("packageName can't be empty");
}
// get pm
PackageManager pm = context.getPackageManager();
Method getPackageSizeInfo = null;
try {
// get method getPackageSizeInfo
getPackageSizeInfo = pm.getClass().getMethod(
"getPackageSizeInfo",
String.class, IPackageStatsObserver.class);
// call method
getPackageSizeInfo.invoke(pm, packageName,
new IPackageStatsObserver.Stub() {
@Override
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
throws RemoteException {
// call listener
listener.onGetSizeInfoCompleted(
new AppSizeInfo(pStats.cacheSize, pStats.dataSize, pStats.codeSize));
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:ittianyu,项目名称:MobileGuard,代码行数:40,代码来源:AppManagerEngine.java
示例11: onCreate
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override
public void onCreate() {
try {
mGetPackageSizeInfoMethod = getPackageManager().getClass()
.getMethod("getPackageSizeInfo", String.class,
IPackageStatsObserver.class);
mFreeStorageAndNotifyMethod = getPackageManager().getClass()
.getMethod("freeStorageAndNotify", long.class,
IPackageDataObserver.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
开发者ID:KouChengjian,项目名称:PhoneMate,代码行数:15,代码来源:CleanerService.java
示例12: initViews
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override
protected void initViews() {
mContext = getActivity();
try {
mGetPackageSizeInfoMethod = mContext.getPackageManager().getClass().getMethod(
"getPackageSizeInfo", String.class, IPackageStatsObserver.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
开发者ID:KouChengjian,项目名称:PhoneMate,代码行数:11,代码来源:SoftwareManageFragment.java
示例13: getPkgSize
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
public static long getPkgSize(final Context context, String pkgName) throws NoSuchMethodException,
InvocationTargetException,
IllegalAccessException {
long pkgSize=0;
// getPackageSizeInfo是PackageManager中的一个private方法,所以需要通过反射的机制来调用
Method method = PackageManager.class.getMethod("getPackageSizeInfo",
new Class[]{String.class, IPackageStatsObserver.class});
// 调用 getPackageSizeInfo 方法,需要两个参数:1、需要检测的应用包名;2、回调
method.invoke(context.getPackageManager(), new Object[]{
pkgName,
new IPackageStatsObserver.Stub() {
@Override
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException {
// 子线程中默认无法处理消息循环,自然也就不能显示Toast,所以需要手动Looper一下
Looper.prepare();
// 从pStats中提取各个所需数据
// pkgSize= pStats.cacheSize+pStats.dataSize+pStats.codeSize;
// Toast.makeText(context,
// "缓存大小=" + Formatter.formatFileSize(context, pStats.cacheSize) +
// "\n数据大小=" + Formatter.formatFileSize(context, pStats.dataSize) +
// "\n程序大小=" + Formatter.formatFileSize(context, pStats.codeSize),
// Toast.LENGTH_LONG).show();
// 遍历一次消息队列,弹出Toast
Looper.loop();
}
}
});
return pkgSize;
}
开发者ID:KouChengjian,项目名称:PhoneMate,代码行数:33,代码来源:Utils.java
示例14: getCacheInfo
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
private void getCacheInfo(PackageInfo packageInfo) {
try {
/**
* ����API
*/
Method method = PackageManager.class.getDeclaredMethod(
"getPackageSizeInfo", String.class,
IPackageStatsObserver.class);
method.invoke(pm, packageInfo.applicationInfo.packageName,
new MyIPackageStatsObserver(packageInfo));
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:yoxin,项目名称:safety,代码行数:15,代码来源:CleanCacheActivity.java
示例15: queryPackageSize
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/** ��ȡָ�����Ĵ�С��Ϣ **/
public void queryPackageSize(String packageName) throws Exception {
Log.i(TAG, "packageName:" + packageName);
if (packageName != null) {
// ʹ�÷�����Ƶõ�PackageManager������غ���getPackageSizeInfo
PackageManager pManager = getPackageManager();
//ͨ��������ƻ�ø����غ���
Method getPackageSizeInfo = pManager.getClass().getMethod("getPackageSizeInfo", String.class,IPackageStatsObserver.class);
//���øú��������Ҹ��������� ��������������ɺ��ص�PkgSizeObserver��ĺ���
getPackageSizeInfo.invoke(pManager, packageName,new PkgSizeObserver());
}
}
开发者ID:loveNight,项目名称:AppInfo,代码行数:13,代码来源:ListAppActivity.java
示例16: getSize
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/**
* Gets the package stats of the given application.
* The package stats are getting sent via OTTO
*
* @param pkg The package name of the application
*/
public static void getSize(final PackageManager pm, final PackageStatsObserver.OnPackageStatsListener l, final String pkg) {
try {
Method m = pm.getClass().getMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);
m.invoke(pm, pkg, new PackageStatsObserver(l));
} catch (Exception e) {
Timber.e(e, "AppHelper.getSize()");
}
}
开发者ID:amartinz,项目名称:DeviceControl,代码行数:15,代码来源:AppHelper.java
示例17: getPackageInfo
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
public void getPackageInfo(String packageName, IPackageStatsObserver.Stub observer) {
try {
PackageManager pm = mAppContext.getPackageManager();
Method getPackageSizeInfo = pm.getClass()
.getMethod("getPackageSizeInfo", String.class, IPackageStatsObserver.class);
getPackageSizeInfo.invoke(pm, packageName, observer);
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:mzlogin,项目名称:AndroidPractices,代码行数:12,代码来源:CacheScanTask.java
示例18: onCreate
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
@Override
public void onCreate() {
try {
mGetPackageSizeInfoMethod = getPackageManager().getClass().getMethod(
"getPackageSizeInfo", String.class, IPackageStatsObserver.class);
mFreeStorageAndNotifyMethod = getPackageManager().getClass().getMethod(
"freeStorageAndNotify", long.class, IPackageDataObserver.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
开发者ID:Frozen-Developers,项目名称:android-cache-cleaner,代码行数:13,代码来源:CleanerService.java
示例19: getPackageSizeInfoAsUser
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/** @hide */
@Override public void getPackageSizeInfoAsUser(String packageName, int userId, IPackageStatsObserver observer) {
mBase.getPackageSizeInfoAsUser(packageName, userId, observer);
}
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:5,代码来源:PackageManagerWrapper.java
示例20: getPackageSizeInfo
import android.content.pm.IPackageStatsObserver; //导入依赖的package包/类
/** @hide */
@Override public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
mBase.getPackageSizeInfo(packageName, observer);
}
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:5,代码来源:PackageManagerWrapper.java
注:本文中的android.content.pm.IPackageStatsObserver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论