I have about 10 apk files to install that need to be installed on an Android device. If you install them separately, it takes a lot of time. Is there a way to install all the applications at once, by clicking on one file?
Is it possible at the same time that after installation on the desktop, shortcuts are automatically created on the applications?
Can I automatically transfer the files I need to the right place for me?
- Collect all your comments in one normal answer, please - Sergeich
- I did, at the beginning of the site I wrote that it was impossible to add an answer, but it turns out you can add a comment and convert it into an answer, after which you can make it normal and expanded. In my opinion, this is not a strong logical and not an example of friendly design. - NeedForS
- and where exactly in the activity to write code to solve the 2nd task? - user7647 2:55 pm
- I wrote in the OnCreate () method - NeedForS
|
2 answers
I did the following: I made another apk file, in it to solve 1 task:
Uri uri = Uri.fromFile("instal.apk"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.android.package-archive"); startActivityForResult(intent,5000);
To solve 2 tasks: In AndroidManifest.xml we write
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
And in the Activity we write:
Intent shortcutIntent = new Intent(); shortcutIntent.setClassName("com.name.package", ".NameActivity"); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY); Intent intentSC = new Intent(); intentSC.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intentSC.putExtra(Intent.EXTRA_SHORTCUT_NAME, "NameShortcut"); intentSC.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeFile("PathToFileIcon.png")); intentSC.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(intentSC);
To solve the third problem:
In AndroidManifest.xml, we write:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
In Activity we write:
public void copyDirectory(File sourceLocation , File targetLocation) throws IOException { if (sourceLocation.isDirectory()) { if (!targetLocation.exists()) { targetLocation.mkdirs(); } String[] children = sourceLocation.list(); for (int i=0; i<children.length; i++) { copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i])); } } else { InputStream in = new FileInputStream(sourceLocation); OutputStream out = new FileOutputStream(targetLocation); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } }
And at the end, in order not to leave traces on the device, we delete ourselves:
Uri packageURI = Uri.parse("package:com.name.apk.package"); Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); startActivity(uninstallIntent); }
|
- Not. It may be noted a few, for example, in the appinstaller and install.
- No, icons are not automatically placed on the desktop, only in the list of applications.
- Not.
|