Wednesday, April 23, 2014

Find Great God help me see this strange problem. . . .


I webview, the realization javascript call java class method, the following code

webView_msg.setVerticalScrollbarOverlay (true);
WebSettings settings = webView_msg.getSettings ();
settings.setSupportZoom (true);
settings.setJavaScriptEnabled (true);
settings.setJavaScriptCanOpenWindowsAutomatically (true);
webView_msg.addJavascriptInterface (new JSInvokeClass (_context), "js2java");

webView_msg.setWebChromeClient (new WebChromeClient ());

webView_msg.loadDataWithBaseURL (null, model.txt, "text / html", "utf-8", null);

I run directly connected to the computer using a mobile phone, you can achieve, but I will after the program package, then install, it can not be achieved, God, please help me look great, thank you. . .
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
What is the error message logcat?
Reply:
After the package is no js effect? alert one a try, this is rarely the case,,,
Reply:
Methods no error code, I used the phone connected to the computer, run directly on the eclipse, click the button in the webview, you can call java class inside

But I will later packaged, install apk, webview click the button again, you can not respond to a java class inside the method. . .
Reply:
Will be installed on your phone to read the js file in the wrong location, or do not have this document.
Reply:
Js files are not going to read, is a piece of html code
loaded directly
webView_msg.loadDataWithBaseURL (null, model.txt, "text / html", "utf-8", null);
Reply:
Their top one. . .
Reply:
Html inside you alert, do not run it?
Reply:
TEST TEST TESTTESTTESTTESTTEST TEST TEST

alert can be executed, but behind that method can not be a
Reply:
lz, you are not packed too confusing? ?

I encountered this problem before because the packaging confusion.
android comes proguard-project.txt, which has explained
# If your project uses WebView with JS, uncomment the following
# And specify the fully qualified class name to the JavaScript interface
# Class:
#-Keepclassmembers class fqcn.of.javascript.interface.for.webview {
# Public *;
#}


You cancel the above shield, and for your Js interface specifies the class name in the following format
-Keep public class . ActivityName $ JSClassname {
public *;
}


No comments:

Post a Comment