0

When I try to install an APK using:

val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE); 
    installIntent.setData(Uri.fromFile(true_path));
    startActivity(installIntent);

I receive the error:

file:///...app-debug.apk exposed beyond app through Intent.getData()

I believe that intents cannot use file:// URIs; how do I build an APK using Android Studio, such that it can be used by an intent?

jlc
  • 1
  • 1
  • It's nothing to do with how you build the apk. It's just that you can no longer send file URIs on `Intent`s. There's an answer with a rather complete example here: https://stackoverflow.com/a/40131196. – Mike M. Jan 16 '19 at 00:55

1 Answers1

-1

The correct way to do it is

File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), 
"application/vnd.android.package-archive");
startActivity(intent);
Navjyot Singh
  • 75
  • 1
  • 11
  • All you've done is make a new file called APK, then used the setDataAndType instead of setData. I am asking how to build the APK such that it is usable by an intent. – jlc Jan 16 '19 at 00:40