2017-10-13 73 views
0

Android Studio新手在这里。 我有一个项目,当按下按钮时,它必须询问用户他们想要打开链接的位置:我的手机的默认浏览器或其他应用程序MyBrowser(它将通过MyBrowser打开浏览器)。但是,当我按下按钮时,它会自动将我带到我的手机的默认浏览器,而不会让用户有机会选择。 这里是我的代码:Android Studio:createChooser帮助

  openWeb = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com")); 
      Intent launchIntent = getPackageManager().getLaunchIntentForPackage("browser.school.mybrowser"); 

      Intent chooser = Intent.createChooser(openWeb, "Please choose which browser..."); 
      if (openWeb != null) { 
       startActivity(chooser); 
      } 
      if (launchIntent != null) { 
       startActivity(launchIntent); 
      } 

回答

1

你有一个意图过滤器添加到活动中来处理应用程序清单文件的请求。检查here

+0

谢谢!这正是我正在寻找的。 – futureLookingGrimm