Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install apk from another program

I'm trying to create an application that automatically downloads an apk from a specific server and install it on the system. My code for the installation looks like the following, but does not work.

File f = new File("/mnt/sdcard/download/", "Demo.apk");
Log.i("Demo", "f "+f.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), "application/vnd.android.package_archive");
intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
m_context.startActivity(intent);            

Do i need to give any rights in Manifest.xml for installation? I know that question has been asked before, but none of the answers have helped me so far.

like image 452
user932865 Avatar asked Dec 03 '22 06:12

user932865


1 Answers

This what I do in my case,

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path+"/<application_name>.apk")), "application/vnd.android.package-archive");
startActivity(intent);

And these are the permissions..

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
like image 88
user370305 Avatar answered Dec 19 '22 21:12

user370305