如何在android webview javascript界面上启动新活动
我正在开发android网络应用程序 我想从javascript开始新的活动。我在谷歌上搜索并找到了显示toast的代码。就是这样如何在android webview javascript界面上启动新活动,javascript,java,android,html,Javascript,Java,Android,Html,我正在开发android网络应用程序 我想从javascript开始新的活动。我在谷歌上搜索并找到了显示toast的代码。就是这样 public class WebAppInterface { Context mContext; /** Instantiate the interface and set the context */ WebAppInterface(Context c) {
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
代码运行良好。但当我尝试开始新的活动时,什么也没有发生。这是我的代码(抱歉英语不好)
试试这个:
在javascript代码中
<script type="text/javascript">
function moveToScreen() {
Android.moveToNextScreen();
}
</script>
将这些添加到onCreate中
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new WebAppInterface(this), "Android");
//Load URL inside WebView
webview.loadUrl("Your html page url");
谢谢你的回答。但是我想从javascript函数开始新的活动。不要在webview上加载一些url。
public void moveToNextScreen(){
//Move to Next screen
Intent newintent = new Intent(FirstActivity.this, SecondIntent.class);
startActivity(newintent);
}
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new WebAppInterface(this), "Android");
//Load URL inside WebView
webview.loadUrl("Your html page url");