I need my application opens when clicking on a link. for this I read that I must use a URL scheme. The link must have the form myapp://parameters.
I read every post on this subject, but when I send an email with "myapp://addUser/?id=22" and I open from chrome (on my phone), it is not clickable.
My manifest:
<activity
android:name="com.example.SplashActivity"
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>
<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="com.example"/>
</intent-filter>
</activity>
My class:
public class SplashActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String id = uri.getQueryParameter("id");
}
}
Content of the mail to test the code:
myapp://addUser/?id=22
Reference Links:
Make a link in the Android browser start up my app?
How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?
https://legacy.madewithmarmalade.com/devnet/forum/custom-url-scheme-primarily-android-3
UPDATE
I think the problem is the mail body, but I don't know how I can test this.
Some app developers publish their universal URLs, and some do not. Not every app has a universal URL. (I.e., It may not be possible to create a 3rd-party app tile in Campus Cloud Studio to launch your app.)
URL Schemes are an advanced configuration option used to define a non-standard link format that will only open in your app and not the device browser e.g. youruniquestring://yoursite.com/path This functionality is helpful in authentication redirect flows or for a more seamless user experience.
In your manifest
<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="com.example"/>
</intent-filter>
you define android:host="com.example", so you should modify link URL :
myapp://addUser/?id=22 //error
myapp://com.example/?id=22 //correct
then it can work!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With