Android权限被忽略

时间:2015-07-29 14:36:38

标签: android android-permissions

我试图从网络浏览器中获取书签列表。这是清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test.permissions"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".BookmarkActivity"
            android:label="@string/title_main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

然而,当实际尝试获取书签时,我得到以下异常:

java.lang.SecurityException: Permission Denial: opening provider com.android.browser.provider.BrowserProvider2 from ProcessRecord{854f860 2449:test.permissions/u0a60} (pid=2449, uid=10060) requires com.android.browser.permission.READ_HISTORY_BOOKMARKS or com.android.browser.permission.WRITE_HISTORY_BOOKMARKS

此外,如果我转到“设置” - >“应用”,请在列表中找到我的应用,它会显示:未请求权限。

我正在使用Android Studio 1.2.2,在Galaxy Nexus AVD API 18上进行调试,我不知道如何调试它。

谢谢!

编辑:aapt d badging <apt_file>的输出是:

package: name='test.permissions' versionCode='1' versionName='1.0' platformBuildVersionName='4.3.1-1425645'
sdkVersion:'8'
targetSdkVersion:'18'
uses-permission: name='com.android.browser.permission.READ_HISTORY_BOOKMARKS'
application-label:'PermissionsLab'
application-icon-120:'res/drawable-ldpi-v4/ic_launcher.png'
application-icon-160:'res/drawable-mdpi-v4/ic_launcher.png'
application-icon-240:'res/drawable-hdpi-v4/ic_launcher.png'
application-icon-320:'res/drawable-xhdpi-v4/ic_launcher.png'
application: label='PermissionsLab' icon='res/drawable-mdpi-v4/ic_launcher.png'
application-debuggable
launchable-activity: name='test.permissions.BookmarkActivity'  label='PermissionsLab' icon=''
feature-group: label=''
  uses-feature: name='android.hardware.touchscreen'
  uses-implied-feature: name='android.hardware.touchscreen' reason='default feature for all apps'
main
other-activities
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '120' '160' '240' '320'

编辑2:执行阅读的代码(不是我写的):

private void loadBookmarks() {

    Log.i(TAG, "Entered loadBookmarks()");

    String text = "";

    Cursor query = getContentResolver().query(Browser.BOOKMARKS_URI,
            projection, null, null, null);

    query.moveToFirst();
    while (query.moveToNext()) {

        text += query.getString(query
                .getColumnIndex(Browser.BookmarkColumns.TITLE));
        text += "\n";
        text += query.getString(query
                .getColumnIndex(Browser.BookmarkColumns.URL));
        text += "\n\n";

    }

    TextView box = (TextView) findViewById(R.id.text);
    box.setText(text);

    Log.i(TAG, "Bookmarks loaded");
}
编辑3:使用最新的软件更新在真正的Nexus 4手机上进行测试,尽管大约需要20秒左右,但仍有效。

2 个答案:

答案 0 :(得分:0)

请告诉我们您运行此测试的位置,是电话,虚拟设备还是其他内容。 From the "READ_HISTORY_BOOKMARKS" documentation已添加权限:

&#34;在API级别4和#34;

中添加

你没有使用:

<uses-sdk android:minSdkVersion="integer"
          android:targetSdkVersion="integer"
          android:maxSdkVersion="integer" />

元素,then from the "elements" documentation 会发生什么:

Caution: If you do not declare this attribute, the system assumes a default value of "1", which indicates that your application is compatible with all versions of Android.

答案 1 :(得分:0)

我最终发现了这个问题:它是API版本。最初,API设置为版本18,证明AVM的名称为Galaxy Nexus API 18。但是,当我为另一个应用程序创建新的AVM时,我注意到API版本已更改为Andoid MNC - Preview。