-3

How can i open APK file recently downloaded from my application?

I tried:

Intent it = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
startActivity(it);

But this didn't work at all it wanted to open it by PDF reader.

public void install(File file){
    if(file.exists()){
    Intent i = new Intent();
    i.setAction(android.content.Intent.ACTION_VIEW);
    i.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    startActivity(i);}
}

With this code i have package error while opening this app.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kowal541
  • 1
  • 2
  • 3
    Already asked here [https://stackoverflow.com/questions/4604239/install-application-programmatically-on-android](https://stackoverflow.com/questions/4604239/install-application-programmatically-on-android) – Roberto Martucci Dec 08 '17 at 23:25
  • 1
    String sdcard = Environment.getExternalStorageDirectory()+ "/download"; Intent promptInstall = new Intent(Intent.ACTION_VIEW) .setDataAndType(Uri.parse(sdcard), "application/vnd.android.package-archive"); startActivity(promptInstall);} this is crashing. – kowal541 Dec 08 '17 at 23:34
  • The app must be installed, in order to be opened. – Phantômaxx Dec 08 '17 at 23:35
  • I want to open apk file in order to let user install it – kowal541 Dec 08 '17 at 23:46

1 Answers1

0

I think your code will run only < N.

For that you have to implement FileProvider,

Dhruv Patel
  • 1,529
  • 1
  • 18
  • 27