android - 当我在地址栏中输入 "myapp://"时,如何从 Android 浏览器启动应用程序

标签 android android-manifest android-intent

每当我在浏览器中输入“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://”网址?

最佳答案

我是用

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

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

希望对您有所帮助。

关于android - 当我在地址栏中输入 "myapp://"时,如何从 Android 浏览器启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4736912/

相关文章:

android - 如何为我的 ListView 中的 ListContents 设置不同的语言

java - Android无法解析或不是字段

java - Android 中如何从另一个应用程序调用或调用一个应用程序?

android - Robolectric 找不到资源或 list 文件

java - 这是启动 Activity 的正确方法吗?

java - 将图像保存到内部存储器

android - 如何在 ANDROID 中完全退出应用程序

android - "com.android.vending.BILLING"和 "android.permission.BILLING"之间的区别

android - 我怎样才能从另一个 Activity 中获得一个 Activity 的 Intent ?

java - 如何在 android 中将蓝牙设备发现超时设置为 1 小时(3600)秒并且从不超时