• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

移动开发中的Scheme跳转说明——Allowing OtherApps to Start Your Activity

Allowing OtherApps to Start Your Activity

 

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

例如豆瓣的scheme:

                 

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

 

 

 

主要的是在于定义了:

 

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


 

和

         

<data
     android:scheme="http"
     android:host="movie.douban.com"
     android:pathPattern="/trailer/.*/"
>
</data>

 

 

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

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

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

 

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

 

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


 

 

 

附件中上传了一个自己写的sheme的demo如果不清楚的可以看看


demo

 

posted @ 2013-09-05 18:59  Class Xman  阅读(547)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3