android-从同一应用程序中调用内容提供者的权限被拒绝
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android-从同一应用程序中调用内容提供者的权限被拒绝,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3529字,纯文字阅读大概需要6分钟。
内容图文
![android-从同一应用程序中调用内容提供者的权限被拒绝](/upload/InfoBanner/zyjiaocheng/665/dd98f2709e704b36b0d5c1fa4835ace3.jpg)
我只有一个应用.它具有未导出的内容提供程序(我不希望其他应用访问该内容),直到现在我已经成功使用了该内容提供程序.
我创建了一个内容观察器来更新TextView.当内容更改时,将调用onChange方法,并尝试重新查询该内容.那是当它收到如下所示的安全异常时:
java.lang.SecurityException: Permission Denial: reading org.sil.lcroffline.data.DataProvider uri content://org.sil.lcroffline/users/by_account_name/5555544444 from pid=0, uid=1000 requires the provider be exported, or grantUriPermission()
这是生成它的代码:
@Override
public void onChange(boolean selfChange, Uri uri) {
Cursor c = null;
try {
c = mContentResolver.query(UserEntry.buildUserPhoneUri(mAccount.name), null, null, null, null);
// do stuff with the data in the cursor
} finally {
if (c != null) c.close();
}
}
URI看起来格式正确,而且我认为在内容提供者中匹配它没有问题.
上面的代码在从应用程序内以编程方式调用时可以正常工作,仅当它是由观察到的数据更改触发而发生异常时.
如何在同一应用程序内获得拒绝权限的信息,该如何解决?
看清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.sil.lcroffline">
<!-- To communicate with LCR -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required because we're manually creating a new account. -->
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".authentication.LoginActivity"
android:label="@string/app_name"
android:exported="true">
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ReportActivity"
android:parentActivityName=".MainActivity"></activity>
<service android:name=".authentication.AuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<provider
android:authorities="@string/data_authority"
android:name=".data.DataProvider"
android:exported="false" />
<service
android:name=".data.SyncService"
android:exported="true"
android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
</application>
</manifest>
解决方法:
原来这是由于我没有在ContentObserver中使用Handler引起的
当您不将处理程序传递给内容观察者时,将直接调用onChange方法,而不是通过处理程序发布消息来调用它.一切都很好,只是在那种情况下调用onChange方法的过程是系统OS,它没有查询我的内容提供者所需的权限.
为了解决这个问题,我更改了从中创建内容观察者的代码:
mUserObserver = new ContentObserver(null) {
// override onChange methods here
}
对此:
mUserObserver = new ContentObserver(new Handler()) {
// override onChange methods here
}
我被this question吸引了
内容总结
以上是互联网集市为您收集整理的android-从同一应用程序中调用内容提供者的权限被拒绝全部内容,希望文章能够帮你解决android-从同一应用程序中调用内容提供者的权限被拒绝所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。