Mr.Sha1
Mr.Sha1

Reputation: 530

How to open a uri in file manager in Android

I'm trying to make a button in my app when user click on it, it'll open a specific URI in file manager but the best I could've done is that the button opens recent tab in default file manager.

Please, if it's possible, suggest me a code which opens a chooser for user to choose between his file manager applications and when user chose, that file manager opens in specific URI that I defined in my code.

Here is my code:

val intent = Intent(Intent.ACTION_GET_CONTENT)
val uri = Uri.parse(
    //my path
)
intent.data = uri
intent.type = "*/*"
startActivity(Intent.createChooser(intent, "Open folder"))

Also one of the users suggested me to use INITIAL_URI I've did it like this but didn't work :

val intent = Intent(Intent.ACTION_GET_CONTENT)
            intent.addCategory(Intent.CATEGORY_OPENABLE)
            val uri = Uri.parse(
                //my path
            )
            intent.data = uri
            intent.type = "*/*"
            intent.putExtra("android.provider.extra.INITIAL_URI", uri)
            intent.putExtra("android.content.extra.SHOW_ADVANCED", true)
            startActivity(Intent.createChooser(intent, "Open folder"))

Upvotes: 1

Views: 1203

Answers (2)

Md. Rakibul Islam
Md. Rakibul Islam

Reputation: 11

fun openNewTabWindow(urls: String, context : Context) {
    val uris = Uri.parse(urls)
    val intents = Intent(Intent.ACTION_VIEW, uris)
    val myV = Bundle()
    myV.putBoolean("new_window", true)
    intents.putExtras(myV)
    context.startActivity(intents)
}

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007554

suggest me a code which opens a chooser for user to choose between his file manager applications and when user chose, that file manager opens in specific URI that I defined in my code

That has never been a pattern in Android app development. There is no standard Intent action for what you seek that is likely to be implemented by much of anything, let alone a significant number of file manager apps.

Upvotes: 2

Related Questions