应用程序在Android 10上崩溃? [英] Application crashes on Android 10?
问题描述
我的应用程序在Play商店上使用了2年,并且运行良好.但是在过去的两周内,突然有用户报告说应用程序在使用时崩溃了.
My application was on Play Store for 2 years and it was running all fine. But suddenly within the past two weeks, users have reported application crashing while using it.
所有崩溃均适用于Android 10用户.
织品日志显示错误为
java.lang.IllegalStateException: Only owner is able to interact with pending media content://media/external/images/media/259525
at android.os.Parcel.createException(Parcel.java:2079)
at android.os.Parcel.readException(Parcel.java:2039)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1687)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1503)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1420)
at android.graphics.ImageDecoder$ContentResolverSource.createImageDecoder(ImageDecoder.java:277)
at android.graphics.ImageDecoder.decodeDrawableImpl(ImageDecoder.java:1743)
at android.graphics.ImageDecoder.decodeDrawable(ImageDecoder.java:1736)
at android.widget.ImageView.getDrawableFromUri(ImageView.java:1022)
at android.widget.ImageView.resolveUri(ImageView.java:991)
at android.widget.ImageView.setImageURI(ImageView.java:568)
at androidx.appcompat.widget.AppCompatImageView.setImageURI(AppCompatImageView.java:116)
at androidx.databinding.adapters.ImageViewBindingAdapter.setImageUri(ImageViewBindingAdapter.java:46)
此屏幕上发生的事情是,用户应该捕获一个屏幕截图.我保存此屏幕截图,并稍后在ImageView
上显示.我通过URI
检索屏幕截图图像.
What's happening at this screen is, The user is supposed to capture a screen-shot. I save this screen-shot and display it later on an ImageView
. I retrieve the screen-shot image by it's URI
.
当我使用图像的URI
检索图像时,发生崩溃.
The crash is happening when I am retrieving the image using it's URI
.
- App Compile SDK版本:28
- App Target SDK版本:28
推荐答案
将文件提供程序用于图像URI.
Use File provider for Image URI.
尝试此代码:
添加代码AndroidManifest.xml
<application>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mypackage.myprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
在res下的xml文件夹中添加provider_paths.xml文件.
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
从活动类的底部代码获取uri.
final Uri data = FileProvider.getUriForFile(context, "myprovider", new File(file_path)); //here your image uri
这篇关于应用程序在Android 10上崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!