react-native-send-intent
react-native-send-intent copied to clipboard
openAppWithUri not working
(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"
},
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!
@tkmin thank you, good sir! You helped a lot