Created
August 22, 2014 03:42
-
-
Save code4lifevn/1d81047b7dcd5af103ac to your computer and use it in GitHub Desktop.
Copy Apk File From Installed App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); | |
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); | |
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0); | |
int z = 0; | |
for (Object object : pkgAppsList) { | |
ResolveInfo info = (ResolveInfo) object; | |
File f1 = new File(info.activityInfo.applicationInfo.publicSourceDir); | |
Log.v("file--", " " + f1.getName().toString() + "----" + info.loadLabel(getPackageManager())); | |
try { | |
String file_name = info.loadLabel(getPackageManager()).toString(); | |
Log.d("file_name--", " " + file_name); | |
// File f2 = new File(Environment.getExternalStorageDirectory().toString()+"/Folder/"+file_name+".apk"); | |
// f2.createNewFile(); | |
File f2 = new File(Environment.getExternalStorageDirectory().toString() + "/MANHDT"); | |
f2.mkdirs(); | |
f2 = new File(f2.getPath() + "/" + file_name + ".apk"); | |
f2.createNewFile(); | |
InputStream in = new FileInputStream(f1); | |
OutputStream out = new FileOutputStream(f2); | |
byte[] buf = new byte[1024]; | |
int len; | |
while ((len = in.read(buf)) > 0) { | |
out.write(buf, 0, len); | |
} | |
in.close(); | |
out.close(); | |
System.out.println("File copied."); | |
} catch (FileNotFoundException ex) { | |
System.out.println(ex.getMessage() + " in the specified directory."); | |
} catch (IOException e) { | |
System.out.println(e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment