The mobile client triggers a webpage event to open the Word

Source: Internet
Author: User

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.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.