Cordova权限需要android.permission.READ_CONTACTS或grantUriPermission()

时间:2015-11-02 22:46:15

标签: cordova phonegap-plugins cordova-plugins visual-studio-cordova

我使用的是Cordova 5.3.1

当我使用contactsprovider.PickContact时,它会返回以下错误

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/raw_contacts from pid=7739, uid=10141 requires android.permission.READ_CONTACTS, or grantUriPermission()

我的androidmanifest.xml是:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="100009" android:versionName="1.0.1" package="io.cordova.myapp557da2" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-sdk android:maxSdkVersion="23" android:minSdkVersion="19" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-feature android:name="android.hardware.telephony" android:required="false" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

我的错误(在这里的单行,我在下面添加了所有内容)

11-02 23:42:08.034  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:08.035  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:08.207   797  3656 I ActivityManager: START u0 {act=android.intent.action.PICK dat=content://com.android.contacts/contacts cmp=com.google.android.contacts/com.android.contacts.activities.ContactSelectionActivity} from uid 10141 on display 0
11-02 23:42:08.235  7126  7126 I ContactsIntentResolver: Called with action: android.intent.action.PICK
11-02 23:42:08.243  7126  7126 E ActionBarOverlayLayout: Requested split action bar with incompatible window decor! Ignoring request.
11-02 23:42:08.368  7739  7778 E Surface : getSlotFromBufferLocked: unknown buffer: 0x9e5aab10
11-02 23:42:08.376   797   815 I ActivityManager: Displayed com.google.android.contacts/com.android.contacts.activities.ContactSelectionActivity: +159ms
11-02 23:42:08.377   797   806 I art     : Background partial concurrent mark sweep GC freed 8060(414KB) AllocSpace objects, 0(0B) LOS objects, 29% free, 37MB/53MB, paused 18.251ms total 93.341ms
11-02 23:42:08.377  1730  1730 I Keyboard.Facilitator: onFinishInput()
11-02 23:42:09.037  6680 26092 D CastSocketMultiplexer: eventCount=0, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=0
11-02 23:42:09.037  6680 26092 D CastSocketMultiplexer: releaseWakeLock
11-02 23:42:09.184  1730  1730 I Keyboard.Facilitator: onFinishInput()
11-02 23:42:09.186  1730  1730 D KeyboardTheme: No property defined for ro.com.google.ime.theme_id
11-02 23:42:09.231  1730  1730 W RichInputMethodSubtype: Can't find emoji subtype
11-02 23:42:09.232  1730  1730 W RichInputMethodSubtype: No input method subtype found; returning dummy subtype: Multi-lingual subtype: android.view.inputmethod.InputMethodSubtype@d78b2ed0, zz
11-02 23:42:09.292  1730  1730 W ViewPager: Requested offscreen page limit 0 too small; defaulting to 1
11-02 23:42:09.293  1730  1730 I Keyboard.Facilitator: onStartInput()
11-02 23:42:09.305  1730  1730 D KeyboardTheme: No property defined for ro.com.google.ime.theme_id
11-02 23:42:09.305  1730  1730 I LatinIME: Starting input. Cursor position = 0,0
11-02 23:42:09.319  1730  1730 I Keyboard.Facilitator: resetDictionaries() : no-op
11-02 23:42:09.319  1730  1730 I StatsUtilsManager: onLoadSettings()
11-02 23:42:11.024  6680  6680 D CastSocketMultiplexer: wakeup
11-02 23:42:11.024  6680 26092 D CastSocketMultiplexer: eventCount=0, wakeLockHeld=false, connectionActionsPending=false, mSockets.size=2, keys.size=0
11-02 23:42:11.024  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=false, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:11.024  6680 26092 D CastSocketMultiplexer: acquireWakeLock
11-02 23:42:11.036  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:11.036  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:11.989   797   806 I art     : Background partial concurrent mark sweep GC freed 7238(311KB) AllocSpace objects, 0(0B) LOS objects, 29% free, 37MB/53MB, paused 1.122ms total 100.591ms
11-02 23:42:12.040  6680 26092 D CastSocketMultiplexer: eventCount=0, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=0
11-02 23:42:12.040  6680 26092 D CastSocketMultiplexer: releaseWakeLock
11-02 23:42:12.822  1730  4782 E Surface : getSlotFromBufferLocked: unknown buffer: 0x98f92a10
11-02 23:42:12.963  7739  7739 D CordovaInterfaceImpl: Sending activity result to plugin
11-02 23:42:12.966  5966 18229 E DatabaseUtils: Writing exception to parcel
11-02 23:42:12.966  5966 18229 E DatabaseUtils: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/raw_contacts from pid=7739, uid=10141 requires android.permission.READ_CONTACTS, or grantUriPermission()
11-02 23:42:12.966  5966 18229 E DatabaseUtils:     at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:605)
11-02 23:42:12.966  5966 18229 E DatabaseUtils:     at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:480)
11-02 23:42:12.966  5966 18229 E DatabaseUtils:     at android.content.ContentProvider$Transport.query(ContentProvider.java:211)
11-02 23:42:12.966  5966 18229 E DatabaseUtils:     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
11-02 23:42:12.966  5966 18229 E DatabaseUtils:     at android.os.Binder.execTransact(Binder.java:453)
11-02 23:42:12.968  7739  7739 D AndroidRuntime: Shutting down VM
11-02 23:42:12.978  7739  7739 E AndroidRuntime: FATAL EXCEPTION: main
11-02 23:42:12.978  7739  7739 E AndroidRuntime: Process: io.cordova.myapp557da2, PID: 7739
11-02 23:42:12.978  7739  7739 E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1000, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/258i23946d8a0b9b54e7.258i51931fc80c8ab400.258i367c82660bd235e7.258i24263260c1808c1.258i314f911d8b5e5441.258i28608deb09e470d5.258i264b6977884338fe.258i657a8d368e4f589b/948 flg=0x1 }} to activity {io.cordova.myapp557da2/io.cordova.myapp557da2.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/raw_contacts from pid=7739, uid=10141 requires android.permission.READ_CONTACTS, or grantUriPermission()
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.ActivityThread.-wrap16(ActivityThread.java)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5417)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-02 23:42:12.978  7739  7739 E AndroidRuntime: Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/raw_contacts from pid=7739, uid=10141 requires android.permission.READ_CONTACTS, or grantUriPermission()
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.os.Parcel.readException(Parcel.java:1599)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.content.ContentResolver.query(ContentResolver.java:491)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.content.ContentResolver.query(ContentResolver.java:434)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at org.apache.cordova.contacts.ContactManager.onActivityResult(ContactManager.java:168)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:120)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:353)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.Activity.dispatchActivityResult(Activity.java:6428)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
11-02 23:42:12.978  7739  7739 E AndroidRuntime:    ... 9 more
11-02 23:42:12.979   797  1349 W ActivityManager:   Force finishing activity io.cordova.myapp557da2/.MainActivity
11-02 23:42:13.029   797   897 I OpenGLRenderer: Initialized EGL, version 1.4
11-02 23:42:13.440   797   806 I art     : Background partial concurrent mark sweep GC freed 7996(398KB) AllocSpace objects, 0(0B) LOS objects, 29% free, 37MB/53MB, paused 3.741ms total 105.265ms
11-02 23:42:13.484   797   810 W ActivityManager: Activity pause timeout for ActivityRecord{70ecab0 u0 io.cordova.myapp557da2/.MainActivity t292 f}
11-02 23:42:13.628  7126  7166 E Surface : getSlotFromBufferLocked: unknown buffer: 0xaefa79d0
11-02 23:42:13.636  7126  7166 D OpenGLRenderer: endAllStagingAnimators on 0x9d383500 (PinnedHeaderListView) with handle 0x9d37efe0
11-02 23:42:13.934   797   810 I ActivityManager: Waited long enough for: ServiceRecord{2cfed98 u0 com.google.android.apps.gesturesearch/.IndexingService}
11-02 23:42:14.027  6680  6680 D CastSocketMultiplexer: wakeup
11-02 23:42:14.027  6680 26092 D CastSocketMultiplexer: eventCount=0, wakeLockHeld=false, connectionActionsPending=false, mSockets.size=2, keys.size=0
11-02 23:42:14.027  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=false, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:14.028  6680 26092 D CastSocketMultiplexer: acquireWakeLock
11-02 23:42:14.041  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:14.042  6680 26092 D CastSocketMultiplexer: eventCount=1, wakeLockHeld=true, connectionActionsPending=false, mSockets.size=2, keys.size=1
11-02 23:42:14.332  7739  7739 I Process : Sending signal. PID: 7739 SIG: 9
11-02 23:42:14.338   797   897 E Surface : getSlotFromBufferLocked: unknown buffer: 0x9162a310
11-02 23:42:14.398   797   890 W InputDispatcher: channel '790a1d3 io.cordova.myapp557da2/io.cordova.myapp557da2.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
11-02 23:42:14.398   797   890 E InputDispatcher: channel '790a1d3 io.cordova.myapp557da2/io.cordova.myapp557da2.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
11-02 23:42:14.402   797  4856 D GraphicsStats: Buffer count: 14
11-02 23:42:14.403   797   808 I WindowState: WIN DEATH: Window{790a1d3 u0 io.cordova.myapp557da2/io.cordova.myapp557da2.MainActivity}
The program '[1] file:///android_asset/www/index.html: WebKit' has exited with code -1 (0xffffffff).
11-02 23:42:14.403   797   808 W InputDispatcher: Attempted to unregister already unregistered input channel '790a1d3 io.cordova.myapp557da2/io.cordova.myapp557da2.MainActivity (server)'
11-02 23:42:14.410   797  4856 I ActivityManager: Process io.cordova.myapp557da2 (pid 7739) has died
11-02 23:42:14.518   797   815 W AppOps  : Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0

1 个答案:

答案 0 :(得分:1)

gradle文件将我的androidmanifest.xml更改为targetSdk 23,后者有一个新的权限系统。

解决方案是更改gradlefile构建属性以将targetsdk设置为22,它使用http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

上解释的旧权限系统