Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openAppWithUri not working #145

Open
tkmin opened this issue Jan 12, 2022 · 2 comments
Open

openAppWithUri not working #145

tkmin opened this issue Jan 12, 2022 · 2 comments

Comments

@tkmin
Copy link

tkmin commented Jan 12, 2022

(at /node_modules/react-native-send-intent/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java)
among below codes

@ReactMethod
    public void openAppWithUri(String intentUri, ReadableMap extras, final Promise promise) {
        try {
            Intent intent = Intent.parseUri(intentUri, Intent.URI_INTENT_SCHEME);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Intent existPackage = this.reactContext.getPackageManager().getLaunchIntentForPackage(intent.getPackage());
            if (existPackage != null) {
                this.reactContext.startActivity(intent);
            } else {
                Intent marketIntent = new Intent(Intent.ACTION_VIEW);
                marketIntent.setData(Uri.parse("market://details?id="+intent.getPackage()));
                marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                this.reactContext.startActivity(marketIntent);
            }
            promise.resolve(true);
        } catch (Exception e) {
            promise.resolve(false);
        }
    }

existPackage is always null,
so App is not opening.

Guessing
this.reactContext.getPackageManager().getLaunchIntentForPackage(intent.getPackage());
is not working at all.

I temporarily replaced

 Intent existPackage = this.reactContext.getPackageManager().getLaunchIntentForPackage(intent.getPackage());
    if (existPackage != null) {
        this.reactContext.startActivity(intent);
    } else {
        Intent marketIntent = new Intent(Intent.ACTION_VIEW);
        marketIntent.setData(Uri.parse("market://details?id="+intent.getPackage()));
        marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.reactContext.startActivity(marketIntent);
    }

to

this.reactContext.startActivity(intent);

and it works fine.

my current versions are

"dependencies": {
    "react": "17.0.2",
    "react-native": "0.66.3",
    "react-native-permissions": "^3.2.0",
    "react-native-send-intent": "^1.3.0",
    "react-native-webview": "^11.15.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/jest": "^26.0.23",
    "@types/react-native": "^0.66.4",
    "@types/react-test-renderer": "^17.0.1",
    "babel-jest": "^26.6.3",
    "eslint": "^7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-test-renderer": "17.0.2",
    "typescript": "^4.4.4"
  },
@tkmin
Copy link
Author

tkmin commented Jan 12, 2022

I rollbacked above's code replacement and
added this code at AndroidManifest.xml file

<manifest>
   ...
    <permission android:name="android.permission.QUERY_ALL_PACKAGES" />
    <queries>
        <intent>
            <action android:name="android.intent.action.MAIN" />
        </intent>
    </queries>
</manifest>

and it works!

@sirmong
Copy link

sirmong commented Dec 13, 2022

@tkmin thank you, good sir! You helped a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants