如何通过网页打开Android APP

如何通过网页打开Android APP

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

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

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <a href="ky://www.keyisoftware.com/vpn?name=daqin&pwd=12345678">打开app</a><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/vpn?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

时间: 2024-08-03 22:31:41

如何通过网页打开Android APP的相关文章

直接通过浏览器打开Android App 应用

点击浏览器中的URL链接,启动特定的App. 首先做成HTML的页面,页面内容格式例如以下: <a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> 这一句就能够了. 当然上面的 在标准形式,对于正常情况而言是OK的.可是每一个浏览器有自己的特定义设置. 各个项目含义例如以下所看到的: scheme:判别启动的App. ※具体后述 host:适当记述 path:传值时必须的key     ※没有也能够 quer

通过浏览器直接打开Android App 应用程序

点击浏览器中的URL链接,启动特定的App. 首先做成HTML的页面,页面内容格式如下: <a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> 这一句就可以了. 当然上面的 在标准形式,对于正常情况而言是OK的,但是每个浏览器有自己的特定义设置. 各个项目含义如下所示: scheme:判别启动的App. ※详细后述 host:适当记述 path:传值时必须的key     ※没有也可以 query:获取值的K

Android应用安全开发之浅谈网页打开APP

一.网页打开APP简介 Android有一个特性,可以通过点击网页内的某个链接打开APP,或者在其他APP中通过点击某个链接打开另外一个APP(AppLink),一些用户量比较大的APP,已经通过发布其AppLink SDK,开发者需要申请相应的资格,配置相关内容才能使用.这些都是通过用户自定义的URI scheme实现的,不过背后还是Android的Intent机制.Google的官方文档<Android Intents with Chrome>一文,介绍了在Android Chrome浏览

Android 通过网页打开自己的APP(scheme)

通过用手机的浏览器(内置,第三方都可)访问一个网页,实现点击一个链接启动自己的应用,并传递数据. 首先在Mainifest文件里面对要启动的Activity添加一个过滤器. <activity android:name="com.example.helloworld.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name=

通过html页面打开Android本地的app

http://www.cnblogs.com/yejiurui/p/3413796.html 一.通过html页面打开Android本地的app 1.首先在编写一个简单的html页面 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title>

推荐下载App,如果本地安装则直接打开本地App(Android/IOS)

推荐下载App,如果本地安装则直接打开本地App(Android/IOS) - 纵观现在每家移动网站,打开首页的时候,都有各种各样的形式来提示你下载自身的移动App(Android/IOS),这是做移动客户端产品的一个很好地引流的手段.当然各家引流下载的交互和视觉各不相同,有的是完全“强奸”用户,有的是完全取悦用户.但是最终的形式就是你点击一个按钮之后,可以去下载对应的App(Android直接下载对应的Apk文件,IOS会跳转到App store的对应地址). 之前开发这个需求的时候,就是很简

Android APP代码拨打电话、打开手机分享功能等隐式意图

Android APP拨打电话: Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110)); startActivity(intent); } Android APP打开电话薄: Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI); startActivity(intent); Android

Android App 第一次打开时的引导界面

Android App 第一次打开时的引导界面,这个需求是非常多的.在写新项目的时候,刚好要用到,在网上找了一下 demo,没发现非满意的.所以只好自己动手写一个,分享一下,避免以后大家重复造轮子.效果图如下(虽然有点丑) 上面这个就是引导界面 GuideActivity 的界面了,实现思路很简单:主界面用 FrameLayout 布局,后面用 ViewPager 装载图片.下面几个小点指示当前滑动到哪个界面了,因为没现在的控制可用,所以自定义了一个 InidcatorView,布局文件如下 <

给你的移动网站加点料:推荐下载App,如果本地安装则直接打开本地App(Android/IOS)

纵观现在每家移动网站,打开首页的时候,都有各种各样的形式来提示你下载自身的移动App(Android/IOS),这是做移动客户端产品的一个很好地引流的手段.当然各家引流下载的交互和视觉各不相同,有的是完全“强奸”用户,有的是完全取悦用户.但是最终的形式就是你点击一个按钮之后,可以去下载对应的App(Android直接下载对应的Apk文件,IOS会跳转到App store的对应地址). 之前开发这个需求的时候,就是很简单的针对用户访问的useragent进行判断,如果android设备,给出的是a