Example usage for android.net.wifi WifiEnterpriseConfig setPassword

List of usage examples for android.net.wifi WifiEnterpriseConfig setPassword

Introduction

In this page you can find the example usage for android.net.wifi WifiEnterpriseConfig setPassword.

Prototype

public void setPassword(String password) 

Source Link

Document

Set the password.

Usage

From source file:tf.nox.wifisetup.WifiSetup.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void applyAndroid43EnterpriseSettings(WifiConfiguration currentConfig,
        HashMap<String, String> configMap) {
    try {/*w w w . jav  a2  s .  com*/
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        InputStream in = getResources().openRawResource(R.raw.cacert);
        // InputStream in = new ByteArrayInputStream(Base64.decode(ca.replaceAll("-----(BEGIN|END) CERTIFICATE-----", ""), 0));
        X509Certificate caCert = (X509Certificate) certFactory.generateCertificate(in);

        WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
        enterpriseConfig.setPhase2Method(Phase2.PAP);
        enterpriseConfig.setAnonymousIdentity(configMap.get(INT_ANONYMOUS_IDENTITY));
        enterpriseConfig.setEapMethod(Eap.TTLS);

        enterpriseConfig.setCaCertificate(caCert);
        enterpriseConfig.setIdentity(s_username);
        enterpriseConfig.setPassword(s_password);
        enterpriseConfig.setSubjectMatch(configMap.get(INT_SUBJECT_MATCH));
        currentConfig.enterpriseConfig = enterpriseConfig;

    } catch (Exception e) {
        e.printStackTrace();
    }
}