8

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.

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

I made a test here and in the manifest file I just removed the "android:host" parameter, leaving this:

<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" />
</intent-filter>

and it opened an URL myapp://testing here that I put on a simple HTML file just for trying.

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.