Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find the "getUriForFile" method in FileProvider

Tags:

android

I am trying to implement a FileProvider to allow me to share local, private images with email and other apps. I have been following the instructions of the Android Developers Guide and get down to where I have to use the "getUriForFile" function and Eclipse tells me I have to create the method. I was under the impression this should be in the android.support.v4.content package and it is in the Referenced Libraries for the app, but it is not there.

I have added the following to my Manifest:

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.gelbintergalactic.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/my_paths" />
</provider>

I have created this xml file:

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

But when I get to this point in my code I am stymied:

Uri contentUri = getUriForFile(this, "com.gelbintergalactic.fileprovider", newfile);

What step am I missing?

like image 255
GeoffSudoku Avatar asked Dec 07 '22 04:12

GeoffSudoku


1 Answers

Yes, instructions in dev guide are not the greatest. getUriForFile() is a static method of the FileProvider class so you need to do:

Uri contentUri =
  FileProvider.getUriForFile(this, "com.gelbintergalactic.fileprovider", newfile);
like image 112
Jim Rhodes Avatar answered Jan 22 '23 20:01

Jim Rhodes