0

how to make in app browser in android studio to open link directly like twitter and instagram.I tried below method which is not giving the desired out come.

   button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY,url);
            startActivity(intent);
        }
    });
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51

1 Answers1

1

this feature is called Chrome Custom Tabs, check out some tutorial how to implement

for gradle:

implementation 'androidx.browser:browser:1.2.0'

code implementation:

Uri uri = Uri.parse("www.google.com");
new CustomTabsIntent.Builder().build().launchUrl(context, uri);
snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • this only works if a user has chrome available on their device though, right ? – a_local_nobody May 31 '22 at 07:43
  • afaik yes, you can detect that with some `ActivityNotFoundException` implementation (in which dev may open e.g. own `Activity` with `WebView`). more info in [HERE](https://stackoverflow.com/questions/43864029/android-chrome-custom-tabs-fallback) – snachmsm May 31 '22 at 09:49