0

I need to open intent with apk file that is downloaded from remote host. On API below 24 everything worked fine and still seems to be ok. Right now I have to target API 29 which is causing me some problems.

When I am trying to open apk file on device with Android 10 everything I got from logs is:

Caught Exception: file:///storage/emulated/0/Download/blablabla.apk exposed beyond app through Intent.getData()

I tried to add FileProvider as suggested here https://stackoverflow.com/a/38858040/717599 or here https://infinum.com/the-capsized-eight/share-files-using-fileprovider

But I am not able to use or import FileProvider as this class is not defined. I tried to

import android.support.v4.content.FileProvider

but package can not be found anywhere. Then I modified my AndroidManifest.xml to include

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.provider" 
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>

But this not magically resolve the issues.

I even tried to disable runtime check as described in here: https://stackoverflow.com/a/42437379/717599

But still without success:

Caught Exception: No Activity found to handle Intent { act=android.intent.action.VIEW 
dat=file:///storage/emulated/0/Download/blablabla.apk typ=application/vnd.android.package-archive flg=0x10000001 }

I have no idea what to do or try to do next except downgrading everything below API 24, which I can not do. Can someone point me what should I do or where I can find any working example? If any additional information is needed or even (not) working demo I will be happy to provide it.

I am using gradle build system that is run from QtCreator.

bialy
  • 193
  • 2
  • 14
  • I was able to add androidx.core.content support instead and finally apk is installed. I will describe everything soon as possible. – bialy Feb 12 '20 at 19:43

1 Answers1

0

To solve that problem add following in application section in AndroidManifest.xml

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS\"
                android:resource="@xml/provider_paths" />
        </provider>

I also created xml file in resources/xml directory with following content:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_download" path="Download"/>
</paths>

Then to build.gradle in block dependencies

compile "com.android.support:support-v4:25.0.+"

Create file gradle.properties (in my case it has not been created by QtCreator). This is part that I was missing - paste this:

android.enableJetifier=true
android.useAndroidX=true 

In java file we can now

import androidx.core.content.FileProvider;

public static void installPackage(String packageLocation){
Uri uriForFile = FileProvider.getUriForFile(
    context, context.getPackageName() + ".fileprovider", new File(packageLocation));
// handle both cases differently - already done in quoted examples
}
bialy
  • 193
  • 2
  • 14