内容提供商:如何授予权限?

时间:2015-12-15 23:17:10

标签: java android permissions

我正在尝试授予其他应用程序的权限。但是否认我试过的是什么?有人可以帮助我添加或更改要在其他包中授予应用程序权限的内容吗?

来自内容提供商的Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="contentprovider.bob3.nl.bob3admin" >

    <application>
        <provider
            android:name=".BusinessLocationsProvider"
            android:authorities="contentprovider.bob3.nl.provider.Locations"
            android:exported="true"
            android:readPermission="contentprovider.bob3.nl.provider.Locations.permission.READ" />
        <activity>
        </activity>
    </application>

</manifest>

内容接收器的Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.a42.cat.philips" >
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="contentprovider.bob3.nl.provider.Locations.permission.READ"/>
    <application>
        <activity android:name=".Intro">
        </activity>
        <activity android:name=".MainActivity" >
        </activity>
    </application>
</manifest>

提供异常的代码

try{
    Uri allTitles = Uri.parse("content://contentprovider.bob3.nl.provider.Locations/company");
    Cursor c;
        //---Honeycomb and later---
        CursorLoader cursorLoader = new CursorLoader(getActivity(), allTitles, null, null, null, null);
        c = cursorLoader.loadInBackground()

        String history = "fail";
        if (c.moveToFirst()) {
            do{
                history = c.getString(c.getColumnIndex("history"));

            } while (c.moveToNext());
        }
    }catch (Exception e){
        Log.e("Catch", e.toString());

    }

来自e.toString()的异常消息:

  

12-16 00:04:15.525 885-885 / com.a42.cat.philips E / Catch:   java.lang.SecurityException:Permission Denial:reading   contentprovider.bob3.nl.bob3admin.BusinessLocationsProvider uri   content://contentprovider.bob3.nl.provider.Locations/company from   pid = 885,uid = 10181需要   contentprovider.bob3.nl.provider.Locations.permission.READ,或   grantUriPermission()

异常消息来自内容提供商

  

12-16 00:04:15.500 24290-24328 / contentprovider.bob3.nl.bob3admin   E / DatabaseUtils:向地块12-16 00:04:15.500写入例外   24290-24328 / contentprovider.bob3.nl.bob3admin E / DatabaseUtils:   java.lang.SecurityException:Permission Denial:reading   contentprovider.bob3.nl.bob3admin.BusinessLocationsProvider uri   content://contentprovider.bob3.nl.provider.Locations/company from   pid = 885,uid = 10181需要   contentprovider.bob3.nl.provider.Locations.permission.READ,或   grantUriPermission()12-16 00:04:15.500   24290-24328 / contentprovider.bob3.nl.bob3admin E / DatabaseUtils:at   android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:467)   12-16 00:04:15.500 24290-24328 / contentprovider.bob3.nl.bob3admin   E / DatabaseUtils:at   android.content.ContentProvider $ Transport.enforceReadPermission(ContentProvider.java:394)   12-16 00:04:15.500 24290-24328 / contentprovider.bob3.nl.bob3admin   E / DatabaseUtils:at   android.content.ContentProvider $ Transport.query(ContentProvider.java:194)   12-16 00:04:15.500 24290-24328 / contentprovider.bob3.nl.bob3admin   E / DatabaseUtils:at   android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)   12-16 00:04:15.500 24290-24328 / contentprovider.bob3.nl.bob3admin   E / DatabaseUtils:at   android.os.Binder.execTransact(Binder.java:404)12-16 00:04:15.500   24290-24328 / contentprovider.bob3.nl.bob3admin E / DatabaseUtils:at   dalvik.system.NativeStart.run(原生方法)

0 个答案:

没有答案