22

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

WorBlux
  • 1,423
  • 11
  • 20
EviatarS
  • 684
  • 2
  • 7
  • 20
  • 2
    Since that's not a valid `Uri` structure, I highly doubt that it will work. It will be simpler for you to change your iOS app to use something that is a valid URI. – CommonsWare Aug 07 '13 at 11:57
  • @CommonsWare Hey, thanks for the comment. This kind of URI works on the IOS app , they manage to open the app by clicking on this link.Do you think that there could only be one scheme like "myapp://" OR "http://" ? – EviatarS Aug 07 '13 at 12:01
  • 1
    "Do you think that there could only be one scheme like "myapp://" OR "http://" ?" -- yes. At best, if you're lucky, `http://` would be treated as the host. At worst, your `Uri` will simply fail to parse. And I can think of a few other options. There absolutely is only one scheme in a `Uri` -- the `Uri` class doesn't allow for more than one. – CommonsWare Aug 07 '13 at 12:16
  • 1
    My read of RFC 2396 is that he has defined an opaque URI scheme, and the fact that the scheme-specific-part looks like another URI is no business of the URI parser. (Also, it's a little glib and unhelpful to suggest "just change your iOS app", likely he's got code in the wild he needs to maintain compatibility with.) – cluesque Dec 11 '13 at 17:02

3 Answers3

18

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>
EviatarS
  • 684
  • 2
  • 7
  • 20
  • It seems straight forward process, however, it doesn't work with me – Mazen Kasser Sep 24 '13 at 00:28
  • @MazenKasser hey , how does your scheme look ? maybe I can help if you post it here – EviatarS Oct 07 '13 at 12:44
  • thanks, I got it working because I wasn't trying the full format "myapp://mydomain.com/" and also found out that not all QR reader apps or the mobile internet browsers does the DeepLinking... – Mazen Kasser Oct 08 '13 at 03:08
  • 2
    myapp:// navigating to app in default browser. but in chrome it is not opening the app. – madan V Jan 07 '14 at 11:23
  • 1
    @madanV where does chrome go to instead of opening the application ? – EviatarS Jan 13 '14 at 13:50
  • 2
    Important note: manually typing the urlscheme into the browser address bar and hitting enter to load it does not work. It DOES work if you CLICK a URL with that urlscheme! – Lane Rettig Sep 17 '16 at 08:55
  • Works like a charm! Make sure to delete `autoVerify="true"` in your `` if you still have that! – SaPropper Oct 17 '21 at 21:11
1

That's a misuse of the URI scheme and is invalid. The HTTP URL you want to pass is a piece of data and should thus be sent in the query string.

myapp://somehost/action?url=http%3A%2F%2Fwww.name.com%2Fpath%2Fpath2%2F
Monstieur
  • 7,992
  • 10
  • 51
  • 77
-1

you need use a hyperlink to start the app . for example ,you set scheme="yourpackagename" ,you need to set a hyperlink like this: yourpackagename://host ,and you should vist the hyperlink on you moble browser .If you do not have host lable,just remove it.

<!-- 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="host" android:scheme="yourpackagename" />
</intent-filter>
<!-- End Test for URL scheme -->

If your activity has more than one scheme, you should use 2 or more to specify it

Yachao
  • 37
  • 3