未解决的类“ FileProvider”

时间:2019-02-27 20:48:15

标签: java android android-fileprovider android-9.0-pie

我正在尝试在Android设备上拍照并跟随this tutorial

以下代码在android.support.v4.content.FileProvider上给我一个错误。 Android studio说未解决的类'FileProvider'

我有以下AndroidManifest.xml文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.camera">

<uses-permission android:name="android.permission.CAMERA" />

<application
    android:label="@string/app_name">

    <activity android:name=".LandingPageActivity" />

    <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" />
    </provider>

</application>

</manifest>

我已将implementation 'com.android.support:support-v4:28.0.0'添加到我的build.gradle文件中。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.camera"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    ...others
    implementation 'com.android.support:support-v4:28.0.0'
}

apply plugin: 'com.google.gms.google-services'

我尝试this solution时没有运气。

2 个答案:

答案 0 :(得分:3)

您使用的是AndroidX依赖项(例如androidx.appcompat依赖项),因此您需要使用AndroidX FileProvider,其包名称为androidx.core.content.FileProvider

<provider
    android:name="androidx.core.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" />
</provider>

答案 1 :(得分:2)

<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>