在做移动应用单点登录的时候,需要在浏览器里点击链接启动APP并将参数传到APP里的相应接口进行处理,现将通过浏览器调用Android和iOS应用的实现过程整理出来固化到博客,以便查询。

一:通过浏览器调用Android应用

1)修改配置文件AndroidManifest.xml,在需要打开的activity下添加如下配置:

<intent-filter>

<data android:scheme="ssotest" /><!-- 通过这个ssotest打开应用程序,可自行定义。 -->
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

2)在HTML中,添加<a href='ssotest://'>ssotest</a>,即可点击此链接打开APP。

3)其他的APP也可以通过如下方式打开该应用:

startActivity(newIntent(Intent.ACTION_VIEW,Uri.parse("ssotest://")));

4)如果想传递参数,可以在url追加即可,比如:

<a href='ssotest://id=123456'>ssotest</a>

5)接受并解析参数,在接收的Activity中使用如下代码获得参数:

this.getIntent().getScheme();//获得Scheme名称

this.getIntent().getDataString();//获得Uri全部路径,根据格式自己解析字符串即可。

二:通过浏览器调用iOS应用

1)修改plist文件,注册对外的URL

A:找到工程的<app>info.plist

B: 点击 information property list后面的加号,从列表中选择URL types

C: 展开URL types,再展开Item0,将Item0下的URL identifier修改为URL Scheme

D: 展开URL Scheme,将Item0的内容修改为ssotest(可自行定义)

2)在HTML中,添加<a href='ssotest://'>ssotest</a>,即可点击此链接打开APP。

3)如果想在启动的APP中接受此URL并进行特殊的处理,可以修改工程的AppDelegate.m,重写openURL方法,如下:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)urlsourceApplication:(NSString *)sourceApplication annotation:(id)annotation

{

// 可通过[url scheme]获得定义的Scheme名称

//可通过[url absoluteString] 获得整个的URL路径,可解析传递过来的数据

}

更多相关文章

  1. Android编程实现自定义ProgressBar样式示例(背景色及一级、二级
  2. Android(安卓)HttpClient GET或者POST请求基本使用方法
  3. 使用PC端chrome 浏览器远程连接android设备调试手机页面
  4. android中对sim卡联系人的增删改查以及监听sim卡联系数据的改变
  5. Android主题和样式系统篇(上)
  6. Android(安卓)2.1学习笔记(一)
  7. Android(安卓)JNI 使用的数据结构JNINativeMethod详解
  8. 秒懂Android注解处理器(Android(安卓)Annotation Processor)
  9. Android.自定义控件的实现

随机推荐

  1. Android(安卓)项目打jar包时遇到包含本地
  2. 解决 EditText 的默认焦点问题
  3. Android(安卓)教你一步步搭建MVP+Retrofi
  4. Android(安卓)Studio增量更新方法
  5. android打开文件、保存对话框、创建新文
  6. 设置文本边框 与 边框的样式:
  7. android网络与通信(三种网络接口简述 )
  8. Android四大组件总结——BoardcastReceiv
  9. Android混淆代码所遇到的坑
  10. Android(安卓)开机动画动态替换