0

I am trying to make an intent that will open com.mozilla.firefox with my link and ignoring the default intent handler for .ACTION_VIEW

My current logic is this:

        Uri uri = formatURL(url); //Turns my string into a URI formatted correctly

        final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.setPackage("com.mozilla.firefox");

        contextActivity.startActivity(intent);

This seems like it should work, but instead does nothing (compared to removing line #3, which opens in Chrome, my default browser). Is it possible to specifically target another app for an intent?

Ali
  • 3,346
  • 4
  • 21
  • 56
ccrama
  • 724
  • 1
  • 8
  • 23
  • The answers here solved my issue! https://stackoverflow.com/questions/8014811/android-launch-firefox-from-within-application – ccrama Apr 02 '18 at 00:43

1 Answers1

0

Try using:

intent.setClassName("packageName", "className");

But it's better to query the activities that can open the intent and launch it

List<ResolveInfo> activities = packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_ALL);

 for (ResolveInfo info :
                activities) {
     if( info.activityInfo.packageName.contains("com.mozilla.firefox")){
           //launch firefox: 
          intent.setClassName(info.activityInfo.packageName,info.activityInfo.name);
          startActivity(intent);         
          }
 }

so if Firefox is not installed you can start your default intent.

Jorge Arimany
  • 5,814
  • 2
  • 28
  • 23