如何从我的应用程序中打开外部URL?

时间:2017-07-29 02:07:47

标签: android uiwebview android-webview

它仍在我的应用中运行。有人能帮我吗 ?如何从我的应用程序中打开外部URL?



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);
			}
		}




1 个答案:

答案 0 :(得分:1)

使用网页视图或重定向网址。

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

之后

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);


    }
}