Skip to content Skip to sidebar Skip to footer

How To Get The Size Of Installed Application?

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).

Solution 1:

try this...

publicstaticlonggetApkSize(Context context, String packageName)throws NameNotFoundException {
    returnnewFile(context.getPackageManager().getApplicationInfo(
            packageName, 0).publicSourceDir).length();
}

Solution 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.

Solution 3:

You can get Size of apps without AIDL Files -------> Kotlin Language

classMainActivity : AppCompatActivity() {
    overridefunonCreate(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)
 }
       
 privatefungetApps(List: MutableList<ResolveInfo>): List<AppData> {
            
     val list = ArrayList<AppData>()
      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 ClassdataclassAppData(val size: Long)

Remember to convert it in MB from Bytes

Post a Comment for "How To Get The Size Of Installed Application?"