展会信息港展会大全

移动开发中的Scheme跳转说明——Allowing OtherApps to Start Your Activity
来源:互联网   发布日期:2016-01-14 10:41:23   浏览:2376次  

导读:Allowing OtherApps to Start Your Activity为了开发更多人使用的App,我们总希望我们的App能够提供一种接口被其他App调用。如我们常见的 大众点...

Allowing OtherApps to Start Your Activity

为了开发更多人使用的App,我们总希望我们的App能够提供一种接口被其他App调用。如我们常见的 大众点评与豆瓣。他们这种资源丰富的App能给我们提供很多丰富的资源。

例如豆瓣的scheme:

[html]

<activity

android:name="com.douban.movie.PlayVideoActivity"

>

<intent-filter>

<action

android:name="com.douban.movie"

>

</action>

<action

android:name="android.intent.action.VIEW"

>

</action>

<category

android:name="android.intent.category.DEFAULT"

>

</category>

<category

android:name="android.intent.category.BROWSABLE"

>

</category>

<data

android:scheme="http"

android:host="movie.douban.com"

android:pathPattern="/trailer/.*/"

>

</data>

</intent-filter>

</activity>

主要的是在于定义了:

[html]

android:name="android.intent.category.BROWSABLE"

[html]

<data

android:scheme="http"

android:host="movie.douban.com"

android:pathPattern="/trailer/.*/"

>

</data>

我们知道,如果用户的手机上没有安装您的App,第三方App如果需要使用Scheme跳转的话就会产生错误。

这个样子的话我们的一般解决办法是直接跳转到网页版的应用上去。

所以,将Scheme写成类似Url的形式方便我们进行应用内的跳转与网页上的跳转。

当然,也可以分开来写,如同大众点评的。

[java]

String id = "3102397";

try

{

Uri url = Uri.parse("dianping://shopinfo?id=" + id);

Intent intent = new Intent(Intent.ACTION_VIEW, url);

mContext.startActivity(intent);

}

catch (Exception e)

{

// 没有安装应用,默认打开HTML5站

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.dianping.com/shop/" + id));

mContext.startActivity(intent);

}

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港