开发者

Is it possible to set up an open URI for Android application?

From this article:

Android Market could be invoked by an ACTION_VIEW intent with URI like

http://market.android.com/details?id=<packagename> 

How does it work? Is the market.android.com return some info to browser to help it open the Android Market application? or just the browser locally does the trick?

Is it possible to set up an open URI who could do the same thing?

For example, I have an app called MyBooks(com.mybooks.app) and a site like:

http://www.mybooks.com

An URL could be

http://www.myboos.com/details?id=0001

and when Browser opens this URL, the site will return some kind of pre-defined response, which might contain an Intent action string, like "com.myboos.app.action.VIEW" and the queried id 0001.

The browser could then try to start an Activity using that action "com.mybooks.app.action.View", if there is an Activity for that, start it and pass the id in. If not, it tries to connect another URL like

http://www.my开发者_运维百科boos.com/details?id=0001&installed=false

Is this possible to work on any version of the Android?


You're actually overthinking this -- the "market.android.com/??" urls never even make it to the Browser, and there's no special data being returned by those URLs. What actually happens is that the system matches the URLs by an Intent filter defined in the Market app before the system Browser ever gets to it. You can read more about Intent filters and how to set up your own in the Android documentation.


Look at this article about Intents and Intent Filters. You should be able to set something like this up in your AndroidManifest.xml.

<activity...>
<intent-filter . . . >
    <category android:name="android.intent.category.BROWSABLE" />
    <data scheme="http" host="www.mybooks.com" path="/details" />
</intent-filter>
</activity>

I've not tried it personally, but I hope this points you in the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜