2

Is there a way to implement OpenUrl functionality(as in iOS OpenUrl) in android?

for example, If a user is redirected from a webpage(in a browser) to "myapp://main", android will launch my app.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
Jesus Dimrix
  • 4,378
  • 4
  • 28
  • 62

3 Answers3

1

the answer is just to add this to manifest inside the activity you want to start :

<activity
    android:name="com.dimrix.something.BootActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>


         <intent-filter>
            <data android:scheme="SomeScheme" />
            <data android:scheme="otherScheme" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
         </intent-filter>


    </activity>

and than if you write inside the browser

SomeScheme://

or

otherScheme://

it will start the activity....

you can even send info after the scheme if you want to do action according to the url by getting the intent data in the activity

Uri data = getIntent().getData();

so you can write

SomeScheme://water

and respond to the "water" as you like with the Uri data .

Jesus Dimrix
  • 4,378
  • 4
  • 28
  • 62
1

Define a Custom URL Scheme, for example to open your SplashScreen Activity when a user type in the browser myapp://main

<activity
    android:name="com.myapp.SplashScreen"
    android:exported="true"
    android:label="@string/app_name"
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <!-- URL scheme -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="myapp" android:host=main" />
    </intent-filter>
    <!--URL scheme -->
</activity>

More info:

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

That can be done with Intent Filters.

See Allowing Other Apps to Start Your Activity in the Android documentation, or answers to this question.

Community
  • 1
  • 1
matiash
  • 54,791
  • 16
  • 125
  • 154