【发布时间】:2014-10-15 04:31:43
【问题描述】:
我在我的应用程序中使用 addJavascriptInterface 从 Javascript 弹出一个共享窗口。
问题是:我在开发环境中使用手机时可以看到弹出窗口。但在发布到 Google 并下载后无法正常工作。我正在使用 Android 4.2 Jellybean mobile 进行测试。
我尝试了几种方法,但都没有奏效。
---------onCreate----------
wvMainMenu = (WebView) findViewById(R.id.wvMainMenu);
wvMainMenu.getSettings().setJavaScriptEnabled(true);
wvMainMenu.getSettings().setLightTouchEnabled(true);
wvMainMenu.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wvMainMenu.addJavascriptInterface(new WebappInterface(this), "Android");
-------Javascript内部----------------
函数 share_it(id) {
Android.share_this(msg[id]);
}
-----WebappInterface.java--------
@Javascript接口 公共无效share_this(字符串str) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
String sharedText = "Text to share " + str;
sendIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
sendIntent.setType("text/plain");
mContext.startActivity(sendIntent);
}
【问题讨论】:
标签: android