enhance(android): use view intent for asset-links

Close #10976
This commit is contained in:
Andelf
2024-02-06 14:22:17 +08:00
parent 03a7b15ff2
commit 37241cc368
3 changed files with 37 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ import android.provider.Settings;
import android.util.Log;
import androidx.activity.result.ActivityResult;
import androidx.core.content.FileProvider;
import androidx.documentfile.provider.DocumentFile;
import com.getcapacitor.JSObject;
@@ -49,6 +50,23 @@ public class FolderPicker extends Plugin {
}
}
@PluginMethod()
public void openFile(PluginCall call) {
Uri uri = Uri.parse(call.getString("uri"));
File file = new File(uri.getPath());
// Get URI and MIME type of file
String appId = getAppId();
uri = FileProvider.getUriForFile(getActivity(), appId + ".fileprovider", file);
String mime = getContext().getContentResolver().getType(uri);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mime);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
getContext().startActivity(intent);
}
@ActivityCallback
private void folderPickerResult(PluginCall call, ActivityResult result) {
if (call == null) {