手机网页唤醒app

手机网页唤醒app,

1、在系统系统自带的浏览器中

  首先做成HTML的页面,页面内容格式如下:    

    <a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> 

  各个项目含义如下所示:

  scheme:判别启动的App。 ※详细后述

  host:适当记述

  path:传值时必须的key     ※没有也可以

  query:获取值的Key和Value  ※没有也可以

例子:<a href="konger://jp.app/openwith?roomId=17">点我跳转空耳</a>

   接下来是Android端。

  首先在AndroidManifest.xml的MAIN Activity下追加以下内容。(启动Activity时给予)

  ※必须添加项  

1

2

3

4

5

6

<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="konger" android:host="jp.app" android:pathPrefix="/openwith"/>

</intent-filter>

 HTML记述的内容加入<data …/>。 

其中必须的内容仅scheme,没有其他内容app也能启动。

※注意事项:intent-filter的内容【android.intent.action.MAIN】和 【android.intent.category.LAUNCHER】这2个,不能与这次追加的内容混合。

所以,如果加入了同一个Activity,请按以下这样做,否则会导致应用图标在桌面消失等问题。 

1

2

3

4

5

6

7

8

9

10

<intent-filter

    <action android:name="android.intent.action.MAIN"/> 

    <category android:name="android.intent.category.LAUNCHER" /> 

</intent-filter

<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="konger" android:host="jp.app" android:pathPrefix="/openwith"/> 

</intent-filter>

 这样的话,没有问题。

 接下来在Activity中需要取值的地方添加以下代码,我是直接写在OnCreate函数里的: 

1

2

3

4

5

6

7

8

9

10

Intent i_getvalue = getIntent(); 

String action = i_getvalue.getAction(); 

   

if(Intent.ACTION_VIEW.equals(action)){ 

    Uri uri = i_getvalue.getData(); 

    if(uri != null){ 

        String name = uri.getQueryParameter("name"); 

        String age= uri.getQueryParameter("age"); 

    

}

这样就能获取到URL传递过来的值了。

2、在第三方的浏览器中

  把一个http服务宿主在本地应用中,本地的服务地址为127.0.0.1:8765中,宿主用于监控服务数据,并打开自身。

3、在微信中打开

  在微信开放平台登记应用之后,可以获得appid,通过这个appid就可以跳转到你的app。
  iOS平台格式如下:appid://openwebview/?ret=0,appid要替换成实际的,后面可以带参数,在你的app可以接收到。
  例如:location.href = wx234ad233ae222://openwebview/?ret=0

IOS系统中实现 

1、在系统自带的浏览器

  

经常使用Safari浏览器浏览网页点击url会唤醒该网站的手机版app

 

需要在app的工程中设置

 

1、打开工程中的myapp-Info.plist文件

 

2、打开文件中新增URL TYPES的一项

 

3、在工程中实现如下方法

1

2

3

4

5

6

7

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    if (url) {

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"你唤醒了您的应用" delegate:selfcancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [alertView show];

    }

    return YES;

 }

4、在Safari浏览器输入konger:// ,就可以启动应用了。  

2、在自身浏览器上显示Banner,有就显示打开,没有就提示下载

<meta name="apple-itunes-app" content="app-id=432274380">

3、在第三方的浏览器中

把一个http服务宿主在本地应用中,本地的服务地址为127.0.0.1:8765中,宿主用于监控服务数据,并打开自身。

4、在微信中打开

在微信开放平台登记应用之后,可以获得appid,通过这个appid就可以跳转到你的app。
iOS平台格式如下:appid://openwebview/?ret=0,appid要替换成实际的,后面可以带参数,在你的app可以接收到。
例如:location.href = wx234ad233ae222://openwebview/?ret=0

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值