Remotely access the Web service on WebView. Click the link on the Web service to open the Word document and edit it.
Public class WebViewUI extends Activity {private WebView webView; private Handler handler = new Handler (); @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // Utils. fullScreen (this); setContentView (R. layout. webview_ui); // Button btnReturn = (Button) findViewById (R. id. btnback); // btnReturn. setOnClickListener (new View. onClickListener () {// @ Override // public void onClick (View v) {// finish (); //}); // regBroadCast (); webView = (WebView) findViewById (R. id. webView); webView. setWebChromeClient (new WebChromeClient (); // webView is required for accessing js on the mobile phone. setWebViewClient (new MyWebViewClient (); // prevents other browsers from prompting webView during page switching. getSettings (). setJavaScriptEnabled (true); webView. addJavascriptInterface (new DemoJavaScriptInterface (), "danielinbiti"); webView. loadUrl (SysConfig. getInstance (). getRootPath () + "web/index.html");} final class DemoJavaScriptInterface {DemoJavaScriptInterface () {} public void clickOnAndroid (String type) {Log. d ("kkkkkkk", type); handler. post (new Runnable () {public void run () {// webView. loadUrl ("javascript: updatewordname('wordname.docx')"); openWord ("test.docx") ;}}} private void openWord (String wordName) {Intent intent = new Intent (); intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); intent. setAction (android. content. intent. ACTION_VIEW); // intent. setClassName ("cn. wps. moffice "," cn.wps.moffice.doc umentmanager. preStartActivity "); // The intent in earlier versions. setClassName ("cn. wps. moffice_eng "," cn.wps.moffice.doc umentmanager. preStartActivity2 "); // String sdPath = Environment. getExternalStorageDirectory () + "/apk/word1.docx"; // Uri uri = Uri. fromFile (new File ("/mnt/sdcard/test.docx"); Uri uri = Uri. fromFile (new File (Environment. getExternalStorageDirectory (), wordName); intent. setData (uri); try {startActivity (intent);} catch (Exception ex) {Log. d ("333333333333", ex. getMessage ());}}}
On js
function callWebView(type){ window.danielinbiti.clickOnAndroid(type); } function updateWordName(name){ document.getElementById('txtareayj').value=name; //alert(name); }
In this way, you can open and edit Word documents online.