简体   繁体   中英

Copy APK file in a folder?

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);
}

To get the .apk file of an application programatically you have to:

  1. Get all installed applications
  2. Get public source directory
  3. Copy the file to the SDCard

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM