How to get the size of installed application?

天大地大妈咪最大 提交于 2019-12-02 12:06:26

问题


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?


回答1:


try this...

public static long getApkSize(Context context, String packageName)
        throws NameNotFoundException {
    return new File(context.getPackageManager().getApplicationInfo(
            packageName, 0).publicSourceDir).length();
}



回答2:


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.



来源:https://stackoverflow.com/questions/21037564/how-to-get-the-size-of-installed-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!