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