未解决的类“FileProvider”

我正在尝试在 android 设备上拍照并按照本教程进行操作。


下面的代码给了我一个错误android.support.v4.content.FileProvider。Android 工作室说Unresolved class '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'

我试过这个解决方案没有运气。


慕沐林林
浏览 242回答 2
2回答

慕莱坞森

您正在使用 AndroidX 依赖项(例如您的androidx.appcompat依赖项),因此您需要使用AndroidX FileProvider,它的包名称为androidx.core.content.FileProvider:<provider&nbsp; &nbsp; android:name="androidx.core.content.FileProvider"&nbsp; &nbsp; android:authorities="${applicationId}.provider"&nbsp; &nbsp; android:exported="false"&nbsp; &nbsp; android:grantUriPermissions="true">&nbsp; &nbsp; <meta-data&nbsp; &nbsp; &nbsp; &nbsp; android:name="android.support.FILE_PROVIDER_PATHS"&nbsp; &nbsp; &nbsp; &nbsp; android:resource="@xml/provider_paths" /></provider>

守候你守候我

<provider&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:name="androidx.core.content.FileProvider"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:authorities="${applicationId}.fileprovider"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:exported="false"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:grantUriPermissions="true">&nbsp; &nbsp; &nbsp; <meta-data&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:name="android.support.FILE_PROVIDER_PATHS"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:resource="@xml/provider_paths" /></provider>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java