已解决
我想在 Android 平板电脑上的网络浏览器应用程序中打开特定 URL。网络浏览器应用程序将从 MyApp 打开。 MyApp 是 webkit Android 应用程序,我可以通过服务器站点上的 jsp 或 js 文件进行编辑。我没有任何 MyApp 来源。 如何从 MyApp 在网络浏览器中打开 URL?
感谢您的理解
[解决方案]
没有办法解决这个问题。移动设备中的 Android 应用程序只能通过另一个具有专有方法和功能的 Android 应用程序进行控制。 JS或者其他任何方式都不能使用Android功能。
我只是不自己解决这个问题,我要求MyApp的开发者编辑他的应用程序。
最佳答案
在布局文件中添加一个webview。使用下面的代码加载 URL
WebView web = (WebView) findViewById(R.id.web);
ProgressDialog progressBar = new ProgressDialog(Activity.this);
progressBar.setMessage("Loading");
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.show();
}
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView webView, int errorCode,
String description, String failingUrl) {
super.onReceivedError(webView, errorCode, description, failingUrl);
try {
webView.stopLoading();
} catch (Exception e) {//
}
if (webView.canGoBack()) {
webView.goBack();
}
AlertDialog alertDialog = new AlertDialog.Builder(Activity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Cannot connect to the Server." +
" Check your internet connection and try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
"Try Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
if (progressBar.isShowing()) {
progressBar.dismiss();
}
alertDialog.show();
}
});
web.loadUrl("your_url");
关于javascript - 如何从 MyApp Android 打开网络浏览器应用程序的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35940377/