zoukankan      html  css  js  c++  java
  • 手机网页唤醒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时给予)

      ※必须添加项  

    <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,请按以下这样做,否则会导致应用图标在桌面消失等问题。 
    <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函数里的: 

    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、在工程中实现如下方法

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

      

      
  • 相关阅读:
    [转]script之defer&async
    css3渐变gradient
    [转]提高 web 应用性能之 CSS 性能调优
    [转]深入了解 CSS3 新特性
    进程中t.start(), t.daemon() t.jion()的使用
    创建进程
    进程与进程之间通信Manager
    简版线程池
    Python上下文管理
    绝版线程池
  • 原文地址:https://www.cnblogs.com/lijuntao/p/8309008.html
Copyright © 2011-2022 走看看