I am trying to adapt my Android application for systems 7.0.0+ it seems that one of the changes is using FileProvider, I am watching tutorials, it seems easy but it turns out that Android Studio 3 does not find this class and I am loading from gradle an android. support.v4 (where I think it's included) such that:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-v4:24.2.0'
implementation 'com.android.support:design:24.2.0'
}
In the AndroidManifest.xml in the application I add the provider and I get the "FileProvider" class in red
<application
...
<provider
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false"
android:authorities="${applicationId}">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths"/>
</provider>
...
And then when I try to use it in an activity it still does not recognize the class.
File file = new File(path + getResources().getString(R.string.downloadFile));
if(Build.VERSION.SDK_INT <= 23){
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
else {
intent.setDataAndType(Uri.fromFile(FileProvider.getUriForFile(this, "com.my.app", file)), "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
What can I do? Thanks.