メインスレッドとWebViewの間の通信を検討してきましたが、何を試しても何も起こらないようです。残念ながら、AndroidではJavascriptデバッグコンソールを用意していません:-/
それはおそらくまたいくつかの愚かな小さな間違いですが、私は問題を見つけることができません。それは単に何もしません。エラーなどは見当たりません。
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
WebView web = (WebView) findViewById (R.id.web);
web.getSettings ().setJavaScriptEnabled (true);
web.setWebChromeClient (new WebChromeClient ());
JavaScriptInterface jsInterface = new JavaScriptInterface (this);
web.addJavascriptInterface (jsInterface, "accessAndroid");
}
public class JavaScriptInterface
{
Context context;
JavaScriptInterface (Context c)
{
context = c;
}
public void gotoArticle (int id)
{
jsHandler.post
(
new Runnable ()
{
public void run ()
{
//TODO//
}
}
);
}
public void showDialog (final String message)
{
jsHandler.post
(
new Runnable ()
{
public void run ()
{
showDialog (message);
}
}
);
}
}
alert ('Something');
ロードされたWebページから実行する場合、すべて問題ありません。しかし、dlg ('Something');
何もしません。