How to extract APK file of installed application in Android programmatically


Step 1 : Get the path of the installed application

// package name of application whose apk you want to extract 
String lStrPackageName = "com.yourapp.packagename";
String lStrApplicationPath = context.getPackageManager()
  .getPackageInfo(lStrPackageName, 0).applicationInfo.publicSourceDir;

Step 2 : Store the Apk file in required folder

//Provide the source path of application
String lStrSourcePath = lStrApplicationPath;
File lObjSource = new File(lStrSourcePath);
//Provide destination path where you want to save APK file
String lStrFinalPath = "/sdcard/YourAppName.apk";
File lObjDestination = new File(lStrFinalPath);
//copy the apk file to required folder
try
{
   FileUtils.copy(new FileInputStream(lObjSource), new FileOutputStream(lObjDestination));
}
catch (IOException e)
{
   e.printStackTrace();
}

Leave A Comment

Your email address will not be published. Required fields are marked *