Reputation: 4568
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.
Upvotes: 2
Views: 2336
Reputation: 126563
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:
Upvotes: 1
Reputation: 4568
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 .
Upvotes: 1
Reputation: 55380
That can be done with Intent Filters.
See Allowing Other Apps to Start Your Activity in the Android documentation, or answers to this question.
Upvotes: 0