我已经研究了大部分自定义 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/