How to get the size of installed application?

2019-03-01 01:49发布

I am trying to calculate the size of the installed application.

I found an answer here

I have tested it on some devices, and there is no problem except Samsung Galaxy Note3(4.3).

I get this error: java.lang.NoSuchMethodException: getPackageSizeInfo()

I'm wondering is there any other way to get the size of an installed app?

2条回答
来,给爷笑一个
2楼-- · 2019-03-01 01:56

try this...

public static long getApkSize(Context context, String packageName)
        throws NameNotFoundException {
    return new File(context.getPackageManager().getApplicationInfo(
            packageName, 0).publicSourceDir).length();
}
查看更多
太酷不给撩
3楼-- · 2019-03-01 02:18

Maybe this link will help you:

http://nsamteladze.blogspot.com/2012/10/get-apks-code-size-in-android.html

Basically he is making use of the concept of reflection, which is a powerful tool but not always advisable. Read more about it here :What is reflection and why is it useful? and if it is suitable for you, make use of it.

查看更多
登录 后发表回答