0

I want to install an apk from my app in android and I did try following

var
 Path: JString;
 Name: JString;
 F: Jfile;
 Intent: JIntent;

   Path := StringToJString(System.IOUtils.TPath.GetSharedDownloadsPath);
   Name := StringToJString('Test.apk');
   F := TJfile.JavaClass.init(Path, Name);

   Intent := TJIntent.Create();
   Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
   Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
   Intent.setDataAndType(TJnet_Uri.JavaClass.fromFile(F), StringToJString('application/vnd.android.package-archive'));

   TAndroidHelper.Context.startActivity(Intent);

and I get android.os.FileUriExposedException: file:///storage/emulated/0/Download/Test.apk exposed beyond app through Intent.getData()

I did try to replase file:// to content:// through ReplaceString but no luck. I did also try following code in setDataAndType package installer starts but getting parsing error.

Intent.setDataAndType(TAndroidHelper.JFileToJURI( TJFile.JavaClass.init(StringToJString(System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetPublicPath,'Test.apk')))),StringToJString('application/vnd.android.package-archive'));

Please help !!!

mesutuk
  • 402
  • 3
  • 17
  • It is not enough to just replace the URL, you have to use a FileProvider to provide access to the file via the new URL, and grant explicit permission for the receiver to use the URL. – Remy Lebeau Jul 03 '21 at 17:37
  • Delphi 10.4 has an option in project settings that do entries in AndroidManifest.xml and generates providers_paths.xml Do I need to do any alteration ? – mesutuk Jul 03 '21 at 17:46

0 Answers0