0

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?

2 Answers 2

6
 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();
    }
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.