Giter VIP home page Giter VIP logo

Comments (7)

anggrayudi avatar anggrayudi commented on September 25, 2024

What's the library version that caused this issue?

from simplestorage.

bonnjalal avatar bonnjalal commented on September 25, 2024

What's the library version that caused this issue?

I use the latest version 1.5.0, but I don't think that the problem from the library itself, I think the problem comes from this package androidx.documentfile.provider
This function return null.

     /**
     * @return file representing newly created document, or null if failed
     */
    @Nullable
    public abstract DocumentFile createFile(@NonNull String mimeType, @NonNull String displayName);

And the same for createFolder.

from simplestorage.

anggrayudi avatar anggrayudi commented on September 25, 2024

Can you copy showGrantedUris() from this file and test it on your project?

private fun showGrantedUris(context: Context, filterStorageId: String) {

I want to see the list of granted URIs on your Xiaomi device.

from simplestorage.

bonnjalal avatar bonnjalal commented on September 25, 2024

Can you copy showGrantedUris() from this file and test it on your project?

private fun showGrantedUris(context: Context, filterStorageId: String) {

I want to see the list of granted URIs on your Xiaomi device.

I tested it and this is what it gives me:
Granted URIs [/storage/emulated/0/Download]


I already testing if the app have access to the chosen URI by user before perform anything else. with this fun:

private fun isStorageUriGranted(storageId: String, basePath: String): Boolean{
        val root = createDocumentUri(storageId, basePath)
        val contentResolver = applicationContext.contentResolver

        return contentResolver.persistedUriPermissions.any {

            it.isReadPermission && it.isWritePermission && it.uri == root
        }
}

from simplestorage.

anggrayudi avatar anggrayudi commented on September 25, 2024

I see... So, your URI is only applicable to Download folder, but you were trying to make folder outside this directory. If you want to create folders inside this path, please use DocumentFileCompat.fromPublicFolder():

val download = DocumentFileCompat.fromPublicFolder(this, PublicDirectory.DOWNLOADS, requiresWriteAccess = true) ?: return
val newFolder = download.makeFolder(this, "Example") ?: return

You'll not be able to access parent from path /storage/emulated/0/Download, because your URI is only limited to this path, hence the parent is always null.

But if you want wider access for Android 10, please grant access to the root path of the storage partition, in this case /storage/emulated/0. In Android 10, if your granted URI is this path, then you'll be able to create folders anywhere in that storage partition.

from simplestorage.

lrq3000 avatar lrq3000 commented on September 25, 2024
val download = DocumentFileCompat.fromPublicFolder(this, PublicDirectory.DOWNLOADS, requiresWriteAccess = true) ?: return
val newFolder = download.makeFolder(this, "Example") ?: return

This appears to not work anymore, failing with a java.lang.NullPointerException when calling the makeFolder() func.

from simplestorage.

lrq3000 avatar lrq3000 commented on September 25, 2024

In fact, the following causes a NullPointerException too on Android 11:

val download = DocumentFileCompat.fromPublicFolder(appContext, PublicDirectory.DOWNLOADS, requiresWriteAccess=true)
Log.d("MyApp", "Debugv Can write to Downloads? " + download!!.canModify(appContext))

/EDIT: the solution here works: #84 (comment)

from simplestorage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.