Stepan
Stepan

Reputation: 97

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. Web browser app will be opened from MyApp. MyApp is webkit Android app which I can edit via jsp or js files on server site. I don't have any source of MyApp. How can I open URL at web browser from MyApp?

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. JS or any other way cannot use Android functions.

I just don't solve this problem by my self, I asked the developer of MyApp to edit his app.

Upvotes: 0

Views: 800

Answers (2)

Harshil Kulkarni
Harshil Kulkarni

Reputation: 411

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;

Upvotes: 0

Balu SKT
Balu SKT

Reputation: 549

In the layout file add a webview. Use below code to load the 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");

Upvotes: 1

Related Questions