简体   繁体   中英

Android: Unable to get provider

I am building a demo app with a content provider. However, this provider cannot be accessed outside the app. I tried to grant the permission mannually, but the app crashes with error message:

java.lang.NullPointerException: Attempt to read from field 'java.lang.String android.content.pm.PackageItemInfo.packageName' on a null object reference
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2379)

Here is my code:

//AndroidManifest.xml
<provider
    android:authorities="com.coffeeshop.android.slicesbasiccodelab"
    android:name="com.coffeeshop.android.slicesbasiccodelab.TemperatureSliceProvider"
    android:grantUriPermissions="true"
    android:exported="true">

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.app.slice.category.SLICE" />
    </intent-filter>
</provider>

// MainActivity.kt
// package com.coffeeshop.android.slicesbasiccodelab
    ...
    // SLICE_VIEWER_PKG = "com.example.mysliceviewer", this is the package name for another app
    // SLICE_URI = "com.coffeeshop.android.slicesbasiccodelab"
    // somewhere when onResume() is finished
    SliceManager.getInstance(this)
        .grantSlicePermission(SLICE_VIEWER_PKG, Uri.parse(SLICE_URI))
    ...
}

Thanks for any help!

solved: slice uri need to be prefixed with "content://"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM