javascript - 如何从 MyApp Android 打开网络浏览器应用程序的 URL

标签 javascript android jsp android-intent

已解决

我想在 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/

相关文章:

javascript - 将 async/await 回调传递给 sass (C++) 会随机崩溃

java - 在消息的对象字段中发送消息

java - 后退按钮转到上一页

android - TableLayout 中的行间距

jsp - JSTL forEach 在 JSP 中不起作用

javascript - 在没有 Canvas 的javascript中使用自定义光标图像动态更改光标大小

javascript - 从php访问json数据

javascript - 如何在 <script setup> Vue3 中使用渲染功能

java - 将文件中的行插入数据库时​​卡住

java - 如何在 Hippo CMS 模板中检查是否为空并显示富文本字段 (HTML)