开发者

How to start app from Android browser, when I type in "myapp://" in address bar

I need the browser to start my app whenever I enter the "myapp://blah.com/a?b=1&c=2" in the browser. I have searched a lot on this topic, but non of the answers really helped me. Could you please help to understand what I'm missing?

<activity android:name=".MyAppMain"
              android:label="@string/app_name"
              android:configChanges="keyboardHidden|orientation" 
              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" /> 
        </intent-filter>
    </activity>

After installation from Eclipse (Run As Android application) my app can work ok on its own, but when I type in "myapp://blah.com/a?b=1&c=2",开发者_开发技巧 the browser is simply googling for this string. Could you point out what else I'm missing? Do I need after installation to somehow register in the system that I want to handle "myapp://" urls?


I have done this using the

  <activity android:name=".ReceiveInviteActivity">

            <intent-filter >
                <category android:name="android.intent.category.BROWSABLE" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />

                 <data
                 android:scheme="appname" 
                 android:host="project.example.com"

                />
            </intent-filter>

        </activity>

And activity

 if (Intent.ACTION_VIEW.equals(action)) {
            final List<String> segments = intent.getData().getPathSegments();
            Log.d("LISTARRAY",segments.toString());
            String idString = segments.get(0);
            Log.d("LISTITEM",segments.get(0).getClass().toString());
            String friendId = idString.substring((idString.indexOf("="))+1);
            Log.d("friendId!",friendId);

I hope this will help you.


Check out this answer for why it isn't working: Android custom URI scheme incorrectly encoded when type in browser

Basically, the default Android browser only accepts certain URI schemes, so your custom one won't work when typed directly into the URL bar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜