Is there any way in Android to force open a link to open in Chrome?

后端 未结 10 1115
情书的邮戳
情书的邮戳 2020-11-28 03:37

I\'m currently testing a webapp developed with lots of jQuery animations, and we\'ve noticed really poor performance with the built-in web browser. While testing in Chrome,

10条回答
  •  温柔的废话
    2020-11-28 04:17

    The different answers above are good but none is complete. This in all suited me the best which will :

    try to open chrome web browser and in case exception occurs(chrome is not default or not installed), will ask for choosing the browser from user:

    String uriString = "your uri string";
    
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setPackage("com.android.chrome");
    try {
        Log.d(TAG, "onClick: inTryBrowser");
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "onClick: in inCatchBrowser", ex );
        intent.setPackage(null);
        startActivity(Intent.createChooser(intent, "Select Browser"));
    }
    

提交回复
热议问题