简体   繁体   English

如何从MyApp Android在Web浏览器应用程序中打开URL

[英]How to open URL at web browser app from MyApp Android

SOLVED 解决了

I want to open specific URL in web browser app on Android tablet. 我想在Android平板电脑上的网络浏览器应用中打开特定的URL。 Web browser app will be opened from MyApp. Web浏览器应用程序将从MyApp打开。 MyApp is webkit Android app which I can edit via jsp or js files on server site. MyApp是Webkit Android应用程序,可以通过服务器站点上的jsp或js文件进行编辑。 I don't have any source of MyApp. 我没有MyApp的任何来源。 How can I open URL at web browser from MyApp? 如何从MyApp在Web浏览器中打开URL?

Thanks for your understanding 感谢您的理解

[Solution] [解]

There is no way how to solve this problem. 没有办法解决这个问题。 Android apps in mobile device can be controlled only via another Android app which has a propriet methods and functions. 只能通过具有适当方法和功能的另一个Android应用程序来控制移动设备中的Android应用程序。 JS or any other way cannot use Android functions. JS或任何其他方式都不能使用Android功能。

I just don't solve this problem by my self, I asked the developer of MyApp to edit his app. 我只是不能自己解决这个问题,而是请MyApp的开发人员编辑他的应用程序。

In the layout file add a webview. 在布局文件中添加一个webview。 Use below code to load the URL 使用以下代码加载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");

Use this code in your app.. 在您的应用中使用此代码。

Intent browserIntent = new 
Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(browserIntent);

As for the missing "http://" I'd just do something like this: 

if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android上通过网络打开应用 - How to open an app from web on Android 从 web 应用程序中使用 Javascript 打开 URL - Open an URL with Javascript from a web app Trigger.io:在Android上使用网络浏览器打开网址 - Trigger.io: Open url with web browser on Android 从应用程序打开单独的浏览器(ios / android) - Open a separate browser from an app(ios/android) 如何从 web 页面打开 android 联系人应用程序? - How can I open android contact app from web page? 在浏览器Cordova Android中打开URL - Open URL in Browser Cordova Android 如何从Firefox OS应用程序在浏览器中打开data:image / png; base64 URL? - How to open a data:image/png;base64 URL in the browser from a Firefox OS app? 通过简单的WebView-App在本机浏览器中打开URL - Open URL in native browser from simple WebView-App 如何在网站中使用 jquery/javascript 检测从 web 浏览器(chrome)或 webview(移动应用程序)打开的 url? - How to detect the url opening from web browser(chrome) or webview(mobile app) using jquery/javascript in the website? 如何防止浏览器在基于脚本的 Web 应用程序的应用程序 URL 中添加用户参数? - How to Prevent Browser from Adding User Parameter in URL Of Apps Script Based Web App?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM