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 Sams
You can get Size of apps without AIDL Files -------> Kotlin Language
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
val list = packageManager.queryIntentActivities(intent,0)
// Set adapter to LIST VIEW
listView.adapter = getApps(list)
}
private fun getApps(List: MutableList): List {
val list = ArrayList()
for (packageInfo in List) {
val packageName = packageInfo.activityInfo.packageName
// return size in form of Bytes(Long)
val size = File(packageManager.getApplicationInfo(packageName,0).publicSourceDir).length()
val item = AppData(Size)
list += item
}
return list
}
}
// Make Data Class
data class AppData(val size: Long)
Remember to convert it in MB from Bytes