安装在物理设备上时应用程序崩溃错误:DISPLAY_NAME列为null



我创建了一个应用程序,并尝试将其安装在物理设备上。当我尝试运行该设备时,它立即崩溃。该应用程序在模拟器中运行良好。我的手机是三星Galaxy A30(安卓11(。应用程序的minSdkVersion为23,targetSdkVersion为31。我的应用程序允许用户创建他们的科目、成绩列表,并为他们的班级创建警报。

我从手机上得到的完整错误:

com.aefyr.sai.model.filedescriptor.ContentUriFileDescriptor$BadContentProviderException: DISPLAY_NAME column is null
at com.aefyr.sai.model.filedescriptor.ContentUriFileDescriptor.name(ContentUriFileDescriptor.java:30)
at com.aefyr.sai.model.apksource.DefaultApkSource.getApkLocalPath(DefaultApkSource.java:47)
at com.aefyr.sai.model.apksource.FilterApkSource.getApkLocalPath(FilterApkSource.java:60)
at com.aefyr.sai.model.apksource.FilterApkSource.nextApk(FilterApkSource.java:28)
at com.aefyr.sai.installer2.impl.rootless.RootlessSaiPackageInstaller.install(RootlessSaiPackageInstaller.java:93)
at com.aefyr.sai.installer2.impl.rootless.RootlessSaiPackageInstaller.lambda$enqueueSession$0$RootlessSaiPackageInstaller(RootlessSaiPackageInstaller.java:70)
at com.aefyr.sai.installer2.impl.rootless.-$$Lambda$RootlessSaiPackageInstaller$ivyAcunEgIkYlu_dB2vN6MOWZPU.run(Unknown Source:6)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)

我认为原因在于Provider。你不能再在Android 11中正常使用某些文件路径了。创建一个类似的文件provider.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_files"
path="." />
</paths>

添加必要的路径(阅读有关内容提供商的信息(。在这之后使用类似Uri:

Uri fileUri = FileProvider.getUriForFile(
requireContext(),
BuildConfig.APPLICATION_ID + ".provider",
file);

添加到清单:

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

您可以提供出现此错误的代码吗?

最新更新