android - 自定义 URL 方案 Android

标签 android url custom-action

嗨,自定义 url 方案对我不起作用。这是我的代码

                <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".MainActivity" android:label="@string/app_name"
        android:launchMode="singleTask">

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:scheme="http" android:host="jinilabs.test" />
        </intent-filter>
    </activity>

</application>

当我在模拟器浏览器上输入 url - http://jinilabs.test 它给我网页不可用错误。 这里有什么问题吗?请告诉我

最佳答案

仅仅在栏中输入 URL 是行不通的。您的 url 必须是网页上的可点击链接,因为检查它是否为自定义 url 的浏览器方法仅在单击链接时触发;它只是运行在地址栏中输入的 url(并忽略自定义 url)。 点击 this link应该按现在的样子启动您的应用程序。如果它仍然不起作用,您可能需要在 list 文件中添加其他代码。我的看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="appcall.thing"
  android:versionCode="1"
  android:versionName="1.0">
  <uses-sdk android:minSdkVersion="4" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".AppCallActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <data android:scheme="stoneware.app.switcher" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
        </intent-filter>
    </activity>
</application>
</manifest>

当然,您必须将此处的一些名称替换为与您的应用相关的名称。我还建议您使用独特的东西而不是 http 开始您的 url 方案,以防 http 混淆浏览器。例如,我的 url 方案是 stoneware.app.switcher:// 希望这对你有用:)

关于android - 自定义 URL 方案 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7876163/

相关文章:

javascript - 如何在地址栏上显示不同网址的新窗口中打开链接

c# - Process.Start() 和用户模拟

android - 动态替换 fragment 而不是在按钮单击或方向更改时

java - 如何解析来自改造请求的以下错误响应?

android - 安装Android Studio后如何修复 "attribute android:layout_width, layout_height and textview not allowed here"

android - 可以在 Android 4 及更高版本上显示来自 URL 的视频缩略图吗?

JavaScript 根据当前 URL 添加类

vbscript - Wix:自定义操作设置的属性的特征条件

windows-8 - 使用 InstallShield 2010 在 Windows 8 上出现 MSI 自定义操作错误 1721

java - 使用 Android Nearby API 检测 Beacon (Eddystone)