During Android development, it takes most of the time to create the interface, and only developers can make it by themselves. Therefore, I have been trying to use HTML5 + css3 to complete the process. phonegap is not quite mature yet, I am going to use Android native + webview to complete the process. I found that it is similar to flash as for mutual debugging. BelowCodeThe Native Interface is called through HTML JavaScript to complete the photo selection code. Click the image to select the image (from the camera or camera ). For the photo selection code, see the previous article.Article《Android photo and Cut Processing Method"
Activity Code:
Import Sh. Path. R;
Import Sh. Path. UI. image. imagecrop;
Import Android. App. activity;
Import Android. content. intent;
Import Android. content. PM. activityinfo;
Import Android. OS. Bundle;
Import Android. OS. Handler;
Import Android. View. view;
Import Android. View. window;
Import Android. WebKit. webview;
Import Android. widget. Toast;
public class htmlfeedhomeactivity extends activity {
private imagecrop photoutil;
private webview = NULL;
private handler mhandler = new handler ();
private string mjsdata = NULL;
private activity activitythis = This;
@ Override
/** Called when the activity is first created .*/
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Requestwindowfeature (window. feature_no_title );
Setcontentview(r.layout.html feeds );
Setupwebview ();
Photoutil = new imagecrop (this );
This. setrequestedorientation (activityinfo. screen_orientation_portrait );
}
Private void setupwebview (){
Webview = (webview) findviewbyid (R. Id. idhtmlfeedhome );
Webview. getsettings (). setjavascriptenabled (true );
Webview. setscrollbarstyle (view. scrollbars_inside_overlay );
Webview. loadurl ("file: // android_asset/path/index.html ");
Webview. addjavascriptinterface (New javascriptinterface (), "Caller ");
}
@ Override
Protected void onactivityresult (INT requestcode, int resultcode, intent data ){
Try {
If (photoutil. capituredimage (requestcode, resultcode, data )){
If (imagecrop. crop_image = requestcode ){
// Mimageview. setimageuri (photoutil. getimagecaptureuricutted ());
Webview. loadurl ("javascript: setphoto ('" + mjsdata + "', '" + photoutil. getimagecaptureuricutted (). getpath () + "')");
}
Return;
}
} Catch (exception exp ){
Exp. printstacktrace ();
}
}
Private class javascriptinterface {
@ Suppresswarnings ("UNUSED ")
Public void clickonandroid (){
Mhandler. Post (New runnable (){
Public void run (){
Webview. loadurl ("javascript: Wave ()");
}
});
}
@ Suppresswarnings ("UNUSED ")
Public void takephoto (string jsdata ){
Mjsdata = jsdata;
Photoutil. getdialog (). Show ();
}
@ Suppresswarnings ("UNUSED ")
Public void showtip (string tip ){
Toast. maketext (activitythis, tip, Toast. length_short). Show ();
}
}
}
For details, see "using HTML5 as the interface and using JavaScript to call a camera instance".