0

My app can currently invoked by all browsers, however there is a requirement that I need to open a webpage in the browser which initially invokes my application.

While the solutions from How can I open a URL in Android's web browser from my application? can launch an intent and let the user choose which browser to response to the intent. I want to let the app opens the same browser that the user previously used to invoke my application (by clicking a web link) so that the user won't be confused and leading to better user experience.

Stephen Fong
  • 697
  • 5
  • 17
  • Does this answer your question? [https://stackoverflow.com/a/37761737/10317684](https://stackoverflow.com/a/37761737/10317684) [getReferrer()](https://developer.android.com/reference/android/app/Activity#getReferrer()) – Ricky Mo Jan 31 '22 at 04:25

2 Answers2

0

There is no guarantee that you can get the name of the calling application. Because the browser you are talking about may not start your application with startActivityForResult however if it did you can get it's package name by

getActivity().getCallingPackage()
Hamed Heidari
  • 174
  • 2
  • 10
0

Try this code :

Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));
ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);

// This is the default browser's packageName String packageName = resolveInfo.activityInfo.packageName;

Praveen Singh
  • 53
  • 1
  • 6