简体   繁体   English

自定义URL方案Android

[英]Custom URL scheme Android

Hi custom url scheme is not working for me. 您好自定义网址方案不适用于我。 Here is my code 这是我的代码

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

when I type the url on the emulator browser - http://jinilabs.test It is giving me web page not available error. 当我在模拟器浏览器上键入url时 - http://jinilabs.test它给了我网页不可用的错误。 Is there anything wrong here? 这里有什么不对吗? Plz let me know Plz让我知道

Simply typing the URL into the bar won't do it. 只需在栏中输入网址即可。 Your url needs to be a clickable link on a webpage because the browser method that checks if it's a custom url only fires when a link is clicked; 您的网址必须是网页上的可点击链接,因为检查它是否为自定义网址的浏览器方法仅在点击链接时才会触发; it simply runs url's that are entered in the address bar(and ignores custom urls). 它只是运行在地址栏中输入的url(并忽略自定义URL)。 Clicking this link should launch your app as it is now. 点击此链接应该按原样启动您的应用。 If it still doesn't work, you may need additional code in your manifest file. 如果它仍然不起作用,您可能需要在清单文件中添加其他代码。 Mine looked like this: 我的看起来像这样:

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

Of course, you will have to substitute some of the names in here for names relative to your app. 当然,您必须用这里的一些名称替换相对于您的应用程序的名称。 I would also recommend starting your url scheme with something unique rather than http in case the http is confusing the browser. 我还建议在http使浏览器混乱的情况下,使用独特而非http的方式启动您的url方案。 My url scheme, for example was stoneware.app.switcher:// Hopefully this can be of some use to you :) 我的网址方案,例如stoneware.app.switcher://希望这对你有用:)

Add this code to manifest file : 将此代码添加到清单文件:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

and then try. 然后试试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM