Reputation: 1
I have a ListView with all the applications installed on the device. Is there a way that on click of the application copy its relative APK in a folder in the phone? Let me explain, for example, i Click the Browser application, copy its APK (Browser.apk) in the Example folder. So I Example / Browser.apk. This is my code for OnClick on Application, that for the moment uninstall the application, but I would replace it with the function of copy APK in a folder.
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
ApplicationInfo app = applist.get(position);
Uri packageUri = Uri.parse("package:"+app.packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
startActivity(uninstallIntent);
}
Upvotes: 0
Views: 377
Reputation: 7061
To get the .apk file of an application programatically you have to:
Note: No need to be rooted.
The snipet code:
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
File file =new File( info.activityInfo.applicationInfo.publicSourceDir);
// Copy the .apk file to wherever
}
Upvotes: 1