【问题标题】:How to start app from Android browser, when I type in "myapp://" in address bar当我在地址栏中输入“myapp://”时,如何从 Android 浏览器启动应用程序
【发布时间】:2011-01-19 15:13:17
【问题描述】:

每当我在浏览器中输入“myapp://blah.com/a?b=1&c=2”时,我都需要浏览器来启动我的应用程序。我在这个话题上搜索了很多,但没有一个答案真的对我有帮助。您能否帮助了解我所缺少的内容?

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

从 Eclipse(运行为 Android 应用程序)安装后,我的应用程序可以自行运行,但是当我输入“myapp://blah.com/a?b=1&c=2”时,浏览器只是在谷歌搜索对于这个字符串。你能指出我还缺少什么吗?安装后是否需要以某种方式在系统中注册我要处理“myapp://”网址?

【问题讨论】:

标签: android android-manifest android-intent


【解决方案1】:

我已经使用了

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

和活动

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

希望对你有帮助。

【讨论】:

    【解决方案2】:

    看看这个答案为什么它不起作用:Android custom URI scheme incorrectly encoded when type in browser

    基本上,默认的 Android 浏览器只接受某些 URI 方案,因此当直接在 URL 栏中键入时,您的自定义方案将不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2012-06-20
      • 1970-01-01
      相关资源
      最近更新 更多