Reputation: 10624
From my native application, I need to open my another app which build by Ionic.
I tried like this,
val intent = packageManager.getLaunchIntentForPackage("com.example.app")
intent.putExtra("uri", "hello 2?")
intent.data = Uri.parse("hello?")
startActivity(intent)
It could launch the app but, it never called handleOpenURL() method.
So I want to try using the custom URL scheme instead of the package name.
How can I open another app using custom URL scheme with URI parameter?
Upvotes: 0
Views: 5272
Reputation: 751
This worked for me. In your android manifest's launcher activity mention the following lines
<intent-filter>
<data android:scheme="http" />
<!-- or you can use deep linking like -->
<data android:scheme="http" android:host="abc.xyz"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Instead of this host name change to suit your preferences and you can use your own scheme as well.
Upvotes: 3
Reputation: 4132
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("YOUR_URL"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, R.string.no_activity_found, Toast.LENGTH_LONG).show();
}
Upvotes: 6