Oreo 中我自己的 URI 上 ContentProvider.notifyChange 的安全异常
Security Exception for ContentProvider.notifyChange on my own URI in Oreo
这个问题之前有人问过 - 但从未回答过。所以我再试试运气。
我的应用程序在同步方面是 Google 的 IO Schedule 应用程序的完美克隆 - 我在 this 位置完全使用他们的代码。
当 运行 针对 SDK 25 时一切正常 - 当我转到 26 时,它崩溃并出现以下异常:
12-28 21:11:13.641 6153-6190/? E/AndroidRuntime: FATAL EXCEPTION: IntentService[DataBootstrapService]
Process: de.XXX.XXX.debug, PID: 6153
java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority
正如其他资源中所建议的那样:是的,我已经为我的内容提供者设置了权限。
这个错误很荒谬。我不知道为什么它会出现 null 和用户 0。
有没有人知道要寻找什么?
谢谢!
您要求提供更多详细信息,但我完全按照 Google 在 IO 计划中所做的那样。
我的 AndroidManifest 包含我的 Provider 如下:
<provider
android:name=".provider.PendelbusProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:syncable="true"/>
导致崩溃的行是这样的:
getContentResolver().notifyChange(Uri.parse(PendelbusContract.CONTENT_AUTHORITY), null, false);
我的CONTENT_AUTHORITY是这样定义的:(间接通过构建变量)
public static final String CONTENT_AUTHORITY = BuildConfig.AUTHORITY;
// equals to: "de.zordid.pendelbus.debug.provider"
我完全不明白该消息应该表示什么。
什么是"provider null",什么是"user 0"?
我的问题的答案在于 URI 的定义以及使用 Uri.getAuthority()
.
派生的权限
将此与 Google 自己的软件中的一个经典 BUG 配对,Google IO Schedule 应用程序是开源的。
在他们的 DataBootstrapService
第 93 行中,他们这样做:
getContentResolver().notifyChange(Uri.parse(ScheduleContract.CONTENT_AUTHORITY), null, false);
但是,我不知道的是:ScheduleContract.CONTENT_AUTHORITY是一个只包含权限的字符串。它没有生成有效的 URI,所以这从一开始就是错误的,并导致了我的问题。
如果你测试这个创建的 Uri 并调用 getAuthority
,你会看到该死的 null
。
修复:使用类似 BASE_CONTENT_URI
的东西,它只有 "content://"+ 权限。那就修好了。
希望这对其他人有帮助。
这个问题之前有人问过 - 但从未回答过。所以我再试试运气。
我的应用程序在同步方面是 Google 的 IO Schedule 应用程序的完美克隆 - 我在 this 位置完全使用他们的代码。
当 运行 针对 SDK 25 时一切正常 - 当我转到 26 时,它崩溃并出现以下异常:
12-28 21:11:13.641 6153-6190/? E/AndroidRuntime: FATAL EXCEPTION: IntentService[DataBootstrapService]
Process: de.XXX.XXX.debug, PID: 6153
java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority
正如其他资源中所建议的那样:是的,我已经为我的内容提供者设置了权限。 这个错误很荒谬。我不知道为什么它会出现 null 和用户 0。
有没有人知道要寻找什么? 谢谢!
您要求提供更多详细信息,但我完全按照 Google 在 IO 计划中所做的那样。
我的 AndroidManifest 包含我的 Provider 如下:
<provider
android:name=".provider.PendelbusProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:syncable="true"/>
导致崩溃的行是这样的:
getContentResolver().notifyChange(Uri.parse(PendelbusContract.CONTENT_AUTHORITY), null, false);
我的CONTENT_AUTHORITY是这样定义的:(间接通过构建变量)
public static final String CONTENT_AUTHORITY = BuildConfig.AUTHORITY;
// equals to: "de.zordid.pendelbus.debug.provider"
我完全不明白该消息应该表示什么。
什么是"provider null",什么是"user 0"?
我的问题的答案在于 URI 的定义以及使用 Uri.getAuthority()
.
将此与 Google 自己的软件中的一个经典 BUG 配对,Google IO Schedule 应用程序是开源的。
在他们的 DataBootstrapService
第 93 行中,他们这样做:
getContentResolver().notifyChange(Uri.parse(ScheduleContract.CONTENT_AUTHORITY), null, false);
但是,我不知道的是:ScheduleContract.CONTENT_AUTHORITY是一个只包含权限的字符串。它没有生成有效的 URI,所以这从一开始就是错误的,并导致了我的问题。
如果你测试这个创建的 Uri 并调用 getAuthority
,你会看到该死的 null
。
修复:使用类似 BASE_CONTENT_URI
的东西,它只有 "content://"+ 权限。那就修好了。
希望这对其他人有帮助。