Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

android - How to listen for a custom URI

I am working on an application which has its own URI prefix. (dchub:// in this case)

Searching all over and read a lot but I got a bit confused.

Is it possible to start my application when someone clicks on a link starting with dchub:// in the browser?

So far found a lot of examples the other way around opening the browser from your app but that's not what I'm looking for.

Update

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(); 
}

I got some nullpointerexceptions 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...