Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL scheme not working in android browser

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.

like image 433
SolArabehety Avatar asked Mar 17 '14 02:03

SolArabehety


People also ask

Does every app have a URL scheme?

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.)

What is URL scheme in 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.


1 Answers

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!!

like image 55
HenryChuang Avatar answered Sep 21 '22 01:09

HenryChuang