Android opens its own app (scheme) via the web

Source: Internet
Author: User

By using the phone's browser (built-in, a third party can) access a Web page, the implementation of clicking a link to launch their own applications, and transfer data.

First, add a filter to the activity that you want to start in the Mainifest file.

<activity            android:name= "com.example.helloworld.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:scheme= "Znn"/>            </intent-filter>        </activity>

Receive data at Mainactivity:

public class Mainactivity extends Activity implements view.onclicklistener{@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Intent Intent = Getintent (); String scheme = Intent.getscheme (); Uri uri = Intent.getdata (); System.out.println ("scheme:" +scheme); if (uri! = null) {String host = Uri.gethost (); String datastring = intent.getdatastring (); String id = uri.getqueryparameter ("id"); String path = Uri.getpath (); String path1 = Uri.getencodedpath (); String queryString = Uri.getquery (); System.out.println ("Host:" +host); System.out.println ("datastring:" +datastring); SYSTEM.OUT.PRINTLN ("ID:" +id); System.out.println ("Path:" +path); System.out.println ("path1:" +path1); System.out.println ("queryString:" +querystring);}}


Write one of the simplest pages:

<a href= "Znn://aa.bb:80/test?p=12&d=1" >test</a>



Test Address: www.erdian.net/m.html

Test results:

Scheme:znn
Host:aa.bb
Datastring:znn://aa.bb:80/test?p=12&id=1
Id:1
Path:/test
Path1:/test

Querystring:p=12&d=1


http://www.erdian.net/?p=238

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.