如何通过网页打开Android APP

1、首先在编写一个简单的html页面

html页面中只有一个简单的连接,代码如下:

<html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>Insert title heretitle>    head>    <body>        <a href="ky://www.keyisoftware.com/?name=daqin&pwd=12345678">打开appa><br/>    body>html>

2、设置APP的AndroidManifest.xml文件

AndroidManifest.xml中需要过滤Intent,配置如下:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="test.keyisoftware.tstartappbyweb"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="14"        android:targetSdkVersion="14" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name=".MainActivity"            android:label="@string/app_name" >            <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:host="www.keyisoftware.com"                    android:scheme="ky" />            intent-filter>        activity>    application>manifest>

注意:android:scheme中的名称必须是全部小写。

3、网页传递数据到APP中

只是打开APP是最为基本的功能,实际的应用中,通常是在打开的时候同时传递相应的参数进去,如实现单点登录,二维码扫描等。

如上面的连接中,传递了对应的用户名和密码:
ky://www.keyisoftware.com/?name=daqin&pwd=12345678

而此时,需要在APP中获取对应的信息,实现代码如下:

package test.keyisoftware.tstartappbyweb;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.widget.Toast;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        // 获取网页传递过来的数据        Intent intent = getIntent();        String scheme = intent.getScheme();        Uri uri = intent.getData();        StringBuffer buffer = new StringBuffer();        if (uri != null) {            // 获取域名,不包含端口            buffer.append("Host=" + uri.getHost());            // 获取传入的全部的字符串            buffer.append("DataString=" + intent.getDataString());            // 获取路径            buffer.append("Path=" + uri.getPath());            // 获取全部的参数            buffer.append("Query=" + uri.getQuery());            // 获取参数的值            buffer.append("Name=" + uri.getQueryParameter("name") + " Pwd=" + uri.getQueryParameter("pwd"));        }        String str = "Scheme=" + scheme + buffer.toString();        Log.i("TStartAppByWeb", str);        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();    }}

注:使用上述方式打开APP的浏览器,内核必须是Webkit。

参考文献:
http://www.cnblogs.com/yejiurui/p/3413796.html
http://blog.csdn.net/jdsjlzx/article/details/37700791

更多相关文章

  1. Android商城购物车页面实现和逻辑实现
  2. android 登陆、提交数据或加载数据时提示页面
  3. Android客户端嵌入html5页面
  4. android 如何判断当前进程在主页面
  5. android之sharedpreference存储参数
  6. Android之检查网络是否可用(跳转网络设置页面)
  7. Android webView 使用back功能返回以前浏览过的页面
  8. android:布局参数,控件属性及各种xml的作用

随机推荐

  1. android NDK环境搭建
  2. android获取手机信息
  3. Android(安卓)Studio下“Error:Could not
  4. Android(安卓)去掉自定义dialog的白色边
  5. 制作Android(安卓)Root Ramdisk
  6. 浅析:Pulltorefresh使用中碰到的问题
  7. Android(安卓)安装路径问题 -- 导致无法
  8. Android中使用全屏
  9. Android中的AnimationSet使用
  10. android ndk编译getevent