第一行代碼(第2版):菜雞踩坑系列----8.3.1調用攝像頭拍照

第一行代碼 8.3.1調用攝像頭拍照

已解決

這一小節中,我在按照書上的代碼編寫後,報了下面的錯誤

java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider:
 java.lang.ClassNotFoundException:
 Didn't find class "android.support.v4.content.FileProvider" on path:
 DexPathList[[zip file "/data/app/com.example.cameraalbumtest-9_-BOJNXp-rnzPlWTdpwGg==/base.apk"],
nativeLibraryDirectories=[/data/app/com.example.cameraalbumtest-9_-BOJNXp-rnzPlWTdpwGg==/lib/arm64, 
/system/lib64, /system/product/lib64]]

這裏的錯誤應該是AndroidManifest.xml文件的內容提供器的聲明有問題。

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

修改爲下面的代碼就可以解決了

		<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.example.cameraalbumtest_8_31.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true"
            >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"/>
        </provider>

原因應該是以前的support包在慢慢的更改成 androidx 這種庫(菜雞的懵逼回答)。
具體原因可以參照博客androidx瞭解一下。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章