react-native-send-intent icon indicating copy to clipboard operation
react-native-send-intent copied to clipboard

Provide a way to openApp with custom intent (instead of package name)

Open yaoliupeloton opened this issue 5 years ago • 1 comments

Hello! This library is very helpful, but I wish there could be another way to open an app. Currently the openApp implementation takes a package name and some extras. It would be great if there's an overloaded method to openApp by an intent directly. So JS send an intent string, and the method just build an intent with that string and opens it.

It'll look like this:

    @ReactMethod
    public void openApp(String customizedIntent) {
        Intent sendIntent = new Intent(customizedIntent);
        if (!parseExtras(extras, sendIntent)) {
            promise.resolve(false);
            return;
        }
        
        sendIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            this.reactContext.startActivity(sendIntent);
            promise.resolve(true);
    }

Thank you!

yaoliupeloton avatar May 23 '19 21:05 yaoliupeloton

Why not try to use WebView to open any apps which you want to open?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    var a = document.createElement('a');
    a.setAttribute('href', 'scheme://scheme');
    a.setAttribute('id', 'openApp');
    // 防止反复添加
    if(document.getElementById('openApp')) {
        document.body.removeChild(document.getElementById('openApp'));
    }
    document.body.appendChild(a);

</script>
</body>
</html>

1uokun avatar May 28 '19 07:05 1uokun