如何监听一个自定义的URI [英] How to listen for a custom URI
问题描述
我工作的一个应用程序至极都有自己的URI preFIX。 (dchub://在这种情况下)
I am working on an application wich has its own URI prefix. (dchub:// in this case)
在搜索遍,读了很多,但我有点糊涂了。
Searching all over and read a lot but I got a bit confused.
是否有可能当有人点击一个链接开始来开始我的应用程序dchub://
在浏览器
Is it possible to start my application when someone clicks on a link starting with dchub://
in the browser?
到目前为止,发现了很多例子otherway各地从您的应用程序打开浏览器,但多数民众赞成我在寻找没有的东西。
So far found a lot of examples the otherway around opening the browser from your app but thats not what I'm looking for.
非常感谢,我已经想通了,现在我有点堵在接下来的部分。
Thanks a lot, i've figured that, now i'm a bit stuck in the next part.
Uri data = getIntent().getData();
if (data.equals(null)) { } else {
String scheme = data.getScheme();
String host = data.getHost();
int port = data.getPort();
}
我得到了一些 NullPointerException异常
如果我启动应用程序通常情况下,它工作得很好,如果我从网页打开秒。因此,我认为让包括一些检查NullValue属性,但没有解决问题。任何建议,我怎么可以通过选择启动应用程序公正?
i got some nullpointerexception
s if i start the app normally, it works fine if i open from the webpage. So i thought lets include some check for nullvalue but that didn't solve it. any suggestions how i can start the app just by selecting it?
推荐答案
要注册一个协议,在你的Android应用程序,添加一个额外的块到AndroidManifest.xml中。
To register a protocol in your android app, add an extra block to the AndroidManifest.xml.
<manifest>
<application>
<activity>
<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="dchub"/>
</intent-filter>
</activity>
</application>
</manifest>
这篇关于如何监听一个自定义的URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!