How to open Android APP via web page

Source: Internet
Author: User

How to open Android APP1 via Web page, first writing a simple HTML page

There is only one simple connection in the HTML page with the following code:

<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">Open app</a><br/>    </body></html>
2. Set the app's Androidmanifest.xml file

Androidmanifest.xml need to filter the intent, configured as follows:

<?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-sdkandroid:minsdkversion="android:targetsdkversion" ="/>"                     <applicationandroid:allowbackup="true"android:icon="@drawable/ Ic_launcher "android:label=" @string/app_name "android:theme=" @style/apptheme " >                                        <activityandroid: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" />                <dataandroid:host= "www.keyisoftware.com"android:scheme=" KY " />                                                    </intent-filter>        </activity>    </Application></manifest>

Note: The name in the Android:scheme must be all lowercase.

3, the Web page to pass data to the app

Just open the app is the most basic function, the actual application, usually in the open at the same time pass the corresponding parameters, such as the realization of single sign-on, QR code scanning and so on.

As in the above connection, the corresponding user name and password are passed:
ky://www.keyisoftware.com/vpn?name=daqin&pwd=12345678

At this point, you need to get the corresponding information in the app, the implementation code is as follows:

 PackageTest.keyisoftware.tstartappbyweb;Importandroid.app.Activity;ImportAndroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.widget.Toast; Public  class mainactivity extends Activity {    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//Get the data that the page passes overIntent Intent = Getintent ();        String scheme = Intent.getscheme ();        Uri uri = Intent.getdata (); StringBuffer buffer =NewStringBuffer ();if(URI! =NULL) {//Get domain name, not including PortBuffer.append ("host="+ Uri.gethost ());//Get all the strings passed inBuffer.append ("datastring="+ intent.getdatastring ());//Get pathBuffer.append ("Path="+ Uri.getpath ());//Get all the parametersBuffer.append ("query="+ uri.getquery ());//Gets the value of the parameterBuffer.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 (); }}

Note: To open the app's browser using the above method, the kernel must be webkit.

Reference documents:
Http://www.cnblogs.com/yejiurui/p/3413796.html
http://blog.csdn.net/jdsjlzx/article/details/37700791

How to open Android APP via web page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.