第一行代码 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了解一下。