简体   繁体   English

Android意图:无论用户使用的是默认浏览器,都在Firefox中打开链接?

[英]Android Intent: Open link in Firefox regardless of user's default browser?

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 我正在尝试创建一个将通过我的链接打开com.mozilla.firefox的意图,而忽略了.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). 看来应该可以,但是什么也没做(与删除第3行相比,该行在我的默认浏览器Chrome中打开)。 Is it possible to specifically target another app for an intent? 是否有可能专门针对其他应用定位目标?

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. 因此,如果未安装Firefox,则可以启动默认意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM