如何获取已安装应用程序的大小?
问题描述:
我正在尝试计算已安装应用程序的大小.
I am trying to calculate the size of the installed application.
我在这里找到了答案
我在一些设备上测试过,除了三星 Galaxy Note3(4.3) 没有问题.
I have tested it on some devices, and there is no problem except Samsung Galaxy Note3(4.3).
我收到此错误:java.lang.NoSuchMethodException: getPackageSizeInfo()
I get this error: java.lang.NoSuchMethodException: getPackageSizeInfo()
我想知道有没有其他方法可以获取已安装应用的大小?
I'm wondering is there any other way to get the size of an installed app?
答
试试这个...
public static long getApkSize(Context context, String packageName)
throws NameNotFoundException {
return new File(context.getPackageManager().getApplicationInfo(
packageName, 0).publicSourceDir).length();
}