0

it is still running within my app. Can someone help me ? how do i open external URL out of my app?

public static void openUrl(final Activity context, final String url) {
   openUrl(context, url, false);
  }

 
  public static void openUrl(final Activity context, final String url, final boolean withoutTransition) {
   final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
   intent.setPackage(getAlternative(context));
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

   context.startActivity(intent);

   if (withoutTransition) {
    context.overridePendingTransition(0, 0);
   }
  }
Naresh
  • 1
  • 2
    Did you consider that this may be a common question, an try searching the site before asking? https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application – Toastrackenigma Jul 29 '17 at 03:28
  • 5
    Possible duplicate of [How can I open a URL in Android's web browser from my application?](https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application) – Toastrackenigma Jul 29 '17 at 03:28

1 Answers1

1

use web view or redirect url.

 Intent intent = new Intent(MainActivity.this, Web_view.class);
                intent.putExtra("url", "https://www.hive.co/contests/contest/5267/spotlight/");
                startActivity(intent);

after this in web view

public class Web_view extends AppCompatActivity {

    private WebView webView;
    private ProgressBar progressBar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_view);
        progressBar = (ProgressBar) findViewById(R.id.progressBar_cyclic);
        String url = getIntent().getStringExtra("url");
        webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);

            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progressBar.setVisibility(View.GONE);
            }
        });
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.loadUrl(url);

        // progressBar.setVisibility(View.GONE);


    }
}
Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
Deep Doshi
  • 77
  • 6