Many applications are now mixed and encounter some HTML pages that open the APK scene. So what are the ways HTML calls Android?
1. If you are developing your own browser app, then HTML page with JS directly with the Android Java interaction can be achieved.
2. If the default system browser accesses HTML, you can choose:
HTML js:window.location.herf= "Www.eg.com"
A:
<activity android:name= ". Detailactivity "> <intent-filter > <data android:scheme=" http "/>
Android:host= "Www.eg.com"
android:pathprefix= "/someresource/" <action android:name= "Android.intent.action.VIEW"/> < Category android:name= "Android.intent.category.BROWSABLE"/> <category android:name= " Android.intent.category.DEFAULT "/> </intent-filter></activity>
As you can see, Android is filtered and selected from the pairing of intent, where we have two choices for the address of the link, and the custom scheme can be in the form of a URL, such as www.example.com or custom content, such as My.custom.scheme.
This approach is very similar to the iOS-side HTML call app, where the HTML section keeps the code consistent.
The custom content, the association is very strong, the user clicks the link only will open the scheme to match the app, in which intent mechanism plays the filtering function, the address must match host,pathprefix and so on the filter condition completely. The general scheme of HTTP is not guaranteed to open directly to your app and may display different app selection pop-up windows.
Custom content may be due to security reasons, in the 4.4 version of the test, Window.location.herf can not open the app, the user manually click the link can be.
The parameters of the link address can be passed with www.eg.com/read?param1=xxx¶m2=xxx. The Java side getintent.getdata gets the URI after the parse parameter.
B:android's own unique approach:
Html:
<a href= "intent: #Intent; action=com.appname.custom_action; S.para1=123456;i.number=4;end ">click to Open</a>
Java:
<activity android:name= ". MyActivity " android:screenorientation=" Sensorlandscape "> <intent-filter> < Action android:name= "Com.appname.CUSTOM_ACTION"/> <category android:name= " Android.intent.category.DEFAULT "/> <category android:name=" Android.intent.category.BROWSABLE "/> </intent-filter></activity>
Intent the custom URI format as follows
Intent:
Host/uri-path//Optional HOST
#Intent;
package=[string];
action=[string];
category=[string];
component=[string];
scheme=[string];
end;
The declaration of the parameter is in the form of a type.varname, a semicolon; a connection
<type>.<key>=<value>
S=StringB=Booleanb=ByteC=CharacterD=DoubleF=FloatI=IntegerL=Longs= Short
such as s.str=sss;i=123;
Method of the ADB command line debug:
ADB shell am start-a android.intent.action.view-d "Http://example.com/gizmos" com.example.android
Where-a-d-C, respectively, represents the action data category
Method Rollup for HTML call Android APK