Recently, the company has a demand, click on the third-party app's H5 page and then jump directly into the app, such as the browser to open a H5 page, and then click on a link directly to the application of a designated activity, after the study found that the implementation is pretty easy, the following method.
First, in the androidmanifest.xml inside the configuration, in the corresponding activity plus a intent-filter, as follows:
<application android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= " @style/apptheme "> <activity android:name=". Mainactivity "android:label=" @string/title_activity_main "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. 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= "Parache S "/> </intent-filter> </activity> </application>
Next, add the relevant parsing code to the corresponding activity, as follows:
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Intent Intent = Getintent (); String action = Intent.getaction (); if (Intent.ACTION_VIEW.equals (ACTION)) {uri uri = Intent.getdata (); 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 (); LOG.D ("Alex", "Host:" +host); LOG.D ("Alex", "datastring:" + datastring); LOG.D ("Alex", "ID:" + ID); LOG.D ("Alex", "Path:" + path); LOG.D ("Alex", "path1:" + path1); LOG.D ("Alex", "queryString:" + queryString); } } }
Look at the log case, as follows:
host:schemedemodatastring:paraches://schemedemo/get/info?id=10000id:10000path:/get/infopath1:/get/ infoquerystring:id=10000
Simple Web page, this page can be opened with a browser, and then click the Jump Link:
<a href= "paraches://schemedemo/get/info?id=10000" >open android app</a>
After the above steps on OK, is not very easy ah, but I believe there may still be a small partner will get lost, here upload a project demo, this page on its own set up, I will not upload, link as follows:
http://download.csdn.net/detail/msn465780/9516335
Click to open link
Android:scheme jump to App app to assign activity via URI