Tuesday 15 January 2013

html5 - how to call HTML at Android? -


I created the new Android app because it displays static information, Strong and off , such as playing MP3 and it will relate to specific days and times. The question is how can I see that this checkbox value on to run MP3 ? .

  Creating a Protected Zero (Bundle Saved Instantstate) {Super.Nought (Saved Instantstate); SetContentView (R.layout.activity_ramadan); // call HTML files webview myWebView = (webview) Find VVBID (RID.web_agine); WebSettings webSettings = myWebView.getSettings (); WebSettings.setJavaScriptEnabled (true); MyWebView.loadUrl ("File: ///android_asset/index.html"); } Public Zero Audioplayer () {// Setup MediaPlayer MediaPlayer mp = New MediaPlayer (); {Try AssetFileDescriptor descriptor = getAssets (). OpenFd ("Azan.mp3"); Mp.setDataSource (descriptor.getFileDescriptor (), descriptor.getStartOffset (), descriptor.getLength ()); Descriptor.close (); Mp.prepare (); Mp.start (); } Hold (exception e) {e.printStackTrace (); }}   

  & lt; Div class = "switch demo 3" & gt; & Lt; Input type = "checkbox" & gt; & Lt; Label & gt; & Lt; I & gt; & Lt; / I & gt; & Lt; / Labels & gt; & Lt; / Div & gt; Simply apply the Java Script interface to communicate between java script and it is possible by your app    

> WebView.addJavascriptInterface () . For example, you can include the following classes in your Android application:

  public class WebAppInterface {context mContext}  

; / ** Instance the interface and set the reference * / WebAppInterface (reference c) {mContext = c; } / ** Web Page * / @ Javascript Interface Show a Toast with Public Zero Show Toast (String Toast) {Toast. Make Text (McIntext, Toast, Toast. LNNGHHORT). Show (); }}

Then in your activity

  get webview webview = (webview) ViewById (R.id.webview); WebView.addJavascriptInterface (New WebAppInterface (this), "Android");  In HTML Now  
  & lt; Input type = "button" value = "say hello" onClick = "showAndroidToast ('Hello Android!')" /> & Lt; Script type = "text / javascript" & gt; Function Show AndroidToast (Toast) {Android. Shostost (toast); } & Lt; / Script & gt;    

No comments:

Post a Comment