Skip to content

[android] opener can only open URLs. #2383

Open
@NyaomiDEV

Description

@NyaomiDEV

When a local app-owned file path is passed to the opener plugin, it will tell us that there's no Activity that can open that uri. This is because FileProvider is not used, therefore a local uri is never converted to a ContentProvider uri, and therefore other apps cannot open our local files.

This code would work btw

import android.content.Intent
import androidx.core.content.FileProvider
import java.io.File
[...]

    fun openPath(path: String) {
        try {
            val file = File(path);
            val uri = FileProvider.getUriForFile(activity, activity.packageName + ".fileprovider", file);
            val intent = Intent(Intent.ACTION_VIEW);
            intent.setData(uri);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            activity.applicationContext?.startActivity(intent);
        }catch (e: Exception){
            
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions