Android how to create Custom URL scheme with the given format myapp://http://

EviatarS picture EviatarS · Aug 7, 2013 · Viewed 35.2k times · Source

I have researched through most of the custom URL scheme Q&A and I have not found my possible answer.

I want my app to be launched by clicking a certain URL in the browser (any on the mobile device) , the thing is that my given URL cannot be modified as it serves IOS app as well and it looks like this:

"myapp://http://www.name.com/path/path2/"

I'm not sure how to handle "myapp://http://" and construct a proper intent filter , and everything i tried does not work. Any help will be appreciated , and if I missed a relevant answer please except my apology.

This is what I tried so far :

      <activity
        android:name="com.myapp.test.SplashScreen"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- Test for 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:host="www.name.com"
                android:path="/path/path2/"
                android:scheme="http" />
            <data
                android:host="www.name.com"
                android:path="/path/path2/"
                android:scheme="https" />

            <data android:scheme="myapp" />
        </intent-filter>
        <!-- End Test for URL scheme -->
    </activity>

Note: I have tried with/without the exported:true

Answer

EviatarS picture EviatarS · Aug 8, 2013

As CommonsWare said the given URI upon I needed to create a Scheme is not a valid URI thus the scheme didn't not work and the application didn't launch. After this explanation the server side guys were convinced to change the URI to myapp://... and it worked like magic :).

The Activity looks like this now :

 <activity
    android:name="com.myapp.test.SplashScreen"
    android:exported="true"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <!-- Test for 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" />
    </intent-filter>
    <!-- End Test for URL scheme -->
</activity>