如何通过单击按钮查看浏览器中的列表

时间:2015-10-09 10:36:51

标签: android

我有一个类似下面代码的活动,我希望当我点击按钮时,我会看到浏览器中的列表,当我选择其中一个时,我会使用所选浏览器访问https://www.google.com网站。我知道我应该使用intent方法,但我不知道如何在我的清单文件和MainActivity.java文件中使用此方法。

public class MainActivity extends Activity {

Button button;
String url = "https://www.google.com";
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }}

2 个答案:

答案 0 :(得分:3)

你可以点击这里按钮点击这里url是你的网址

private static final String HTTPS = "https://";
private static final String HTTP = "http://";

  button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
         // To check if url starts with http or https if not then will throw an exception
         if (!url.startsWith(HTTP) && !url.startsWith(HTTPS)) {
           url = HTTP + url;
         }
         Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
         startActivity(Intent.createChooser(intent, "Choose browser"));

      }
    });


}

答案 1 :(得分:0)

<bindings>

      <customBinding>
        <binding name="MyCustomBinding">
          <binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                                 maxSessionSize="2048">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                     maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          </binaryMessageEncoding>        
          <textMessageEncoding
            messageVersion="Soap11WSAddressingAugust2004"/>
         <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                         maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
         bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
        keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true"/>
        </binding>

      </customBinding>

    </bindings>

<services>
      <service name="ADHA.ADHAServiceApi" >
  <endpoint address="" binding="customBinding" bindingConfiguration="MyCustomBinding" contract="ADHA.IADHAService">
            </endpoint>
         <endpoint address="mex" binding="customBinding" contract="IMetadataExchange" />

      </service>      
    </services>

<extensions>
      <bindingExtensions>
        <!--<add name="ProxyElement" type="ADHA.Model.HttpTransportBindingElementProxy, ADHA"/>-->
      <add name="MyCustomBinding" type="ADHA.Model.MyCustomBindingCollectionElement,ADHA,
               Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </bindingExtensions>
    </extensions>