Android 如何使用给定格式 myapp ://http://创建自定义 URL 方案

标签 android url android-manifest intentfilter url-scheme

我已经研究了大部分自定义 URL 方案问答,但没有找到可能的答案。

我希望通过单击浏览器中的某个 URL(移动设备上的任何 URL)来启动我的应用程序,问题是我给定的 URL 无法修改,因为它也服务于 IOS 应用程序,它看起来像这样:

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

我不确定如何处理“myapp://http://”并构造一个适当的 Intent 过滤器,我尝试的一切都不起作用。 任何帮助将不胜感激,如果我错过了相关答案,请除了我的道歉。

这是我迄今为止尝试过的:

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

注意:我试过有/没有exported:true

最佳答案

正如 CommonsWare 所说,在我需要创建方案时给定的 URI 不是有效的 URI,因此方案不起作用并且应用程序没有启动。在这个解释之后,服务器端的人被说服将 URI 更改为 myapp://... 它就像魔术一样工作:)。

Activity 现在看起来像这样:

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

关于Android 如何使用给定格式 myapp ://http://创建自定义 URL 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18102528/

相关文章:

php - 是否可以记住第一页的网址并将其用作返回第二页的链接 - PHP

url - URL路径的大小写和间距的最佳做法是什么?

c# - 如何在 xamarin android 中扩展应用程序类

java - 在 Android Studio 1.0 之后,values-21、values-22 或 values-xx 文件夹消失了

java - 当 onBackPressed() 被覆盖时保留过渡动画

java - 如何删除xml布局背景中的空格?

javascript - 将 URL 添加到一页 Web 应用程序

android - 使用 startInstrumentation 检测 Android 应用程序

android - 谷歌播放 : Application is not compatible

android - 如何解决Android View Pager内存不足异常?