要获取有关问题的信息,我尝试使用隐藏的Api(使用AIDL),它在低于26的Api中有效,但在26或27以下的Api中不起作用。
java.lang.UnsupportedOperationException: Shame on you for calling the hidden API getPackageSizeInfoAsUser(). Shame!
我做到了: http://allandroidprojects.blogspot.com/2016/06/android-get-cache-size-data-size-apk.html
此解决方案已被接受,但在oreo中不起作用:
该帖子中提到的另一个解决方案是:
final PackageManager pm = context.getPackageManager();
ApplicationInfo applicationInfo = pm.getApplicationInfo(appInfo.getPackage(), 0);
File file = new File(applicationInfo.publicSourceDir);
int size = file.length();
通过使用上述方法,我无法获得所有应用程序的大小,因为它仅给我基本apk大小,而没有给我其他应用程序内容,例如:
log:
2019-07-02 11:48:16.082 4069-4069/com.example.getallinstallapp D/AppSize: :com.android.cts.priv.ctsshim:6044
2019-07-02 11:48:16.098 4069-4069/com.example.getallinstallapp D/AppSize: :/system/priv-app/GoogleExtServices/GoogleExtServices.apk
2019-07-02 11:48:16.099 4069-4069/com.example.getallinstallapp D/AppSize: :Android Services Library:10924
2019-07-02 11:48:16.154 4069-4069/com.example.getallinstallapp D/AppSize: :/data/app/com.example.voicelockreenginer-nhzu_JLVE6Eh5C-sfg-asg==/base.apk
2019-07-02 11:48:16.154 4069-4069/com.example.getallinstallapp D/AppSize: :VoiceScreenLock:144984
2019-07-02 11:48:16.163 4069-4069/com.example.getallinstallapp D/AppSize: :/system/app/CubeLiveWallpapers/CubeLiveWallpapers.apk
2019-07-02 11:48:16.163 4069-4069/com.example.getallinstallapp D/AppSize: :Example Wallpapers:22868
2019-07-02 11:48:16.169 4069-4069/com.example.getallinstallapp D/AppSize: :/system/priv-app/TelephonyProvider/TelephonyProvider.apk
2019-07-02 11:48:16.169 4069-4069/com.example.getallinstallapp D/AppSize: :Phone and Messaging Storage:137053
2019-07-02 11:48:16.196 4069-4069/com.example.getallinstallapp D/AppSize: :/system/priv-app/CalendarProvider/CalendarProvider.apk
2019-07-02 11:48:16.196 4069-4069/com.example.getallinstallapp D/AppSize: :Calendar Storage:127531
2019-07-02 11:48:16.202 4069-4069/com.example.getallinstallapp D/AppSize: :/system/priv-app/MediaProvider/MediaProvider.apk
2019-07-02 11:48:16.202 4069-4069/com.example.getallinstallapp D/AppSize: :Media Storage:133272
2019-07-02 11:48:16.214 4069-4069/com.example.getallinstallapp D/AppSize: :/system/priv-app/GoogleOneTimeInitializer/GoogleOneTimeInitializer.apk
2019-07-02 11:48:16.214 4069-4069/com.example.getallinstallapp D/AppSize: :Google One Time Init:58568
2019-07-02 11:48:16.229 4069-4069/com.example.getallinstallapp D/AppSize: :/system/app/GoogleExtShared/GoogleExtShared.apk
2019-07-02 11:48:16.229 4069-4069/com.example.getallinstallapp D/AppSize: :Android Shared Library:4774
2019-07-02 11:48:16.236 4069-4069/com.example.getallinstallapp D/AppSize: :/system/priv-app/WallpaperCropper/WallpaperCropper.apk
2019-07-02 11:48:16.236 4069-4069/com.example.getallinstallapp D/AppSize: :com.android.wallpapercropper:25986
在这里,VoiceScreenLock:144984
的大小约为144 kb,但实际大小约为13.5至14 MB。
上面提到的方法也会返回正确的apk大小。因此,为了更清晰起见,我进入了设备浏览器。https://ibb.co/r2ys3ZW
如您所见,要获得整个应用程序的大小,我需要合并该文件夹中所有.apk的结果。
如何获得适当的应用大小和有问题的其他信息?