Example usage for android.content Context WIFI_SERVICE

List of usage examples for android.content Context WIFI_SERVICE

Introduction

In this page you can find the example usage for android.content Context WIFI_SERVICE.

Prototype

String WIFI_SERVICE

To view the source code for android.content Context WIFI_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access.

Usage

From source file:ch.bfh.instacircle.NetworkInfoFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

    // get the network managers
    WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    AdhocWifiManager adhoc = new AdhocWifiManager(wifi);

    super.onViewCreated(view, savedInstanceState);
    dbHelper = NetworkDbHelper.getInstance(getActivity());
    preferences = getActivity().getSharedPreferences(PREFS_NAME, 0);

    // set the labels accordingly
    layout = (GridLayout) getView().findViewById(R.id.network_info_layout);
    networkSSID = (TextView) layout.findViewById(R.id.network_ssid);
    networkPassword = (TextView) layout.findViewById(R.id.network_password);
    participantIdentification = (TextView) layout.findViewById(R.id.participant_identification);
    ipAddress = (TextView) layout.findViewById(R.id.ip_address);
    broadcastAddress = (TextView) layout.findViewById(R.id.broadcast_address);

    networkSSID.setText(preferences.getString("SSID", "N/A"));
    networkPassword.setText(dbHelper.getCipherKey());
    participantIdentification.setText(preferences.getString("identification", "N/A"));
    ipAddress.setText(adhoc.getIpAddress().getHostAddress());
    broadcastAddress.setText(adhoc.getBroadcastAddress().getHostAddress());
}

From source file:eu.vranckaert.worktime.utils.network.NetworkUtil.java

/**
 * Checks if the device is connected to a WiFi network or not.
 * @param ctx The app-context./*ww w  . ja v a 2 s  .co  m*/
 * @return {@link Boolean#TRUE} if the device is connected to a WiFi network, {@link Boolean#FALSE} otherwise.
 */
public static boolean isConnectedToWifi(Context ctx) {
    WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager != null) {
        SupplicantState state = wifiManager.getConnectionInfo().getSupplicantState();
        if (state != null) {
            NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf(state);
            if (detailedState != null) {
                if (detailedState == NetworkInfo.DetailedState.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:ch.bfh.instacircle.service.NetworkService.java

@Override
public void onDestroy() {

    // Stop everything if the leave message is coming from myself
    try {//from w ww  .  j a  v a 2s  . co  m
        for (int i = 0; i < tcpUnicastReceiverThreads.length; i++) {
            tcpUnicastReceiverThreads[i].interrupt();
            udpBroadcastReceiverThreads[i].interrupt();
            tcpUnicastReceiverThreads[i].serverSocket.close();
            udpBroadcastReceiverThreads[i].socket.close();
        }
    } catch (Exception e) {

    }

    dbHelper.closeConversation();

    WifiManager wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    new AdhocWifiManager(wifiman).restoreWifiConfiguration(getBaseContext());
    WifiAPManager wifiAP = new WifiAPManager();
    if (wifiAP.isWifiAPEnabled(wifiman)) {
        wifiAP.disableHotspot(wifiman, getBaseContext());
    }
    stopSelf();
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    // Unregister the receiver which listens for messages to be sent
    LocalBroadcastManager.getInstance(this).unregisterReceiver(messageSendReceiver);

    // close the DB connection
    dbHelper.close();
    super.onDestroy();
}

From source file:com.ultrafunk.network_info.service.NetworkStateService.java

@Override
public void onCreate() {
    super.onCreate();

    //   Log.e(this.getClass().getSimpleName(), "onCreate()");

    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        mobileDataSettingUri = Uri.withAppendedPath(Settings.System.CONTENT_URI, "mobile_data");
    else//from  w  w  w  .j a  va2  s.  c  om
        mobileDataSettingUri = Uri.withAppendedPath(Settings.Global.CONTENT_URI, "mobile_data");

    initEnabledWidgets(Utils.getEnabledWidgets(this, AppWidgetManager.getInstance(this)));
}

From source file:org.wso2.emm.agent.services.DeviceNetworkStatus.java

private DeviceNetworkStatus(final Context context) {
    this.context = context;
    wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    receiverWifi = new WifiReceiver();

    // Register broadcast receiver
    // Broacast receiver will automatically call when number of wifi connections changed
    context.registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    // start scanning wifi
    startWifiScan();/*  w  w w. j av  a  2 s .  c om*/

    info = getNetworkInfo(context);
    mapper = new ObjectMapper();
}

From source file:com.example.multi_ndef.frag_wifi.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_wifi, container, false);

    mSpinner = (Spinner) v.findViewById(R.id.spinner);
    mSpinner.setOnItemSelectedListener(this);

    mEditText1 = (EditText) v.findViewById(R.id.editText1);
    fr = (CNFCInterface) getActivity().getApplication();

    WifiManager wifi;/*w  ww .  j a v a  2 s  .c om*/
    try {
        wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);

        // Get WiFi status
        WifiInfo info = wifi.getConnectionInfo();
        // List available networks

        wifi.startScan();
        List<ScanResult> results;
        results = wifi.getScanResults();
        int array_length = results.size();
        int i = 0;
        String[] values = new String[array_length];
        for (ScanResult result : results) {
            values[i] = result.SSID;
            i = i + 1;
        }

        Set<String> set = new HashSet<String>();
        Collections.addAll(set, values);
        String[] uniques = set.toArray(new String[0]);
        int length = uniques.length;

        List<String> SpinnerArray = new ArrayList<String>();

        for (int i1 = 1; i1 < length; i1++) {
            SpinnerArray.add(uniques[i1]);
        }

        // Create an ArrayAdapter using the string array and a default

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),
                android.R.layout.simple_spinner_item, SpinnerArray);
        // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        mSpinner.setAdapter(adapter);

    } catch (Exception e) {
        Toast toast = Toast.makeText(getActivity().getApplicationContext(), "Turn on the wifi",
                Toast.LENGTH_SHORT);
        toast.show();

    }

    return v;
}

From source file:in.codehex.facilis.LoginActivity.java

/**
 * Initialize the objects.//from  ww w . j a  va 2  s  .  c  o m
 */
private void initObjects() {
    editEmail = (EditText) findViewById(R.id.edit_email);
    editPass = (EditText) findViewById(R.id.edit_pass);
    textForgotPass = (TextView) findViewById(R.id.text_forgot_pass);
    btnLogin = (Button) findViewById(R.id.btn_login);

    userPreferences = getSharedPreferences(Config.PREF_USER, MODE_PRIVATE);
    mProgressDialog = new ProgressDialog(this);
    mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    mWifiInfo = mWifiManager.getConnectionInfo();
}

From source file:com.tejus.shavedog.HttpServerServiceImpl.java

@Override
public void onCreate() {
    super.onCreate();

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    httpServer = new HttpServer(new AndroidLocalInetAddressResolver(wifiManager));

    if (!Util.ANDROID_EMULATOR) {
        registerReceiver(connectivityReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }//  w  w w  . j a v a 2 s . c  o  m
}

From source file:com.example.qrpoll.MainActivity.java

@Override
/**// w  w w.j av  a2 s . c  o m
 * tworzenie startowego widoku aplikacji
 */
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    scanBtn = (Button) findViewById(R.id.scan_button);
    button1 = (Button) findViewById(R.id.button1);
    formatTxt = (TextView) findViewById(R.id.scan_format);
    contentTxt = (TextView) findViewById(R.id.scan_content);

    scanBtn.setOnClickListener(this);
    SqlHandler sql = new SqlHandler(getApplication());
    sql.open();
    sql.close();
    if (!checkNetwork()) {
        if (!checkWifi()) {
            AlertDialog.Builder adb = new AlertDialog.Builder(this);
            adb.setTitle("Brak polaczenia");
            adb.setMessage("Nacisnij ok aby wlaczyc WIFI").setCancelable(false).setNeutralButton("OK",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                            wifi.setWifiEnabled(true);
                        }
                    });
            AlertDialog ad = adb.create();
            ad.show();
        }
    }
}

From source file:biz.easymenu.easymenung.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.settings, container, false);

    String strVersion = "";

    PackageInfo packageInfo;/*from www .jav  a2 s  .  co  m*/
    try {
        packageInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        strVersion = packageInfo.versionName;
    } catch (NameNotFoundException e) {
        //e.printStackTrace();
        strVersion = "Cannot load Version!";
    }

    WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String macAddress = wifiInfo == null ? "" : wifiInfo.getMacAddress();

    ((EditText) v.findViewById(R.id.txtVersion)).setText(strVersion);
    ((EditText) v.findViewById(R.id.txtMac)).setText(macAddress);
    (etServer = (EditText) v.findViewById(R.id.txtServer)).setText(emp.getValue("server"));
    (etPassword = (EditText) v.findViewById(R.id.txtPassword)).setText(emp.getValue("password"));

    rg = (RadioGroup) v.findViewById(R.id.rgSync);
    pbar = (ProgressBar) v.findViewById(R.id.pBarSync);

    btnSync = (Button) v.findViewById(R.id.btnSync);
    btnSave = (Button) v.findViewById(R.id.btnConfSave);
    btnClose = (Button) v.findViewById(R.id.btnConfClose);

    btnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            emp.setKeyValue("server", etServer.getText().toString());
            emp.setKeyValue("password", etPassword.getText().toString());
            emp.commit();

            /*FragmentManager fm = getActivity().getSupportFragmentManager();
             FragmentTransaction ft ;
             Fragment f = null;
             if(fm.findFragmentByTag("rightfragment")!=null){
              ft = fm.beginTransaction();
              ft.setCustomAnimations(android.R.anim.fade_in,
                  android.R.anim.fade_out);
              ft.remove(fm.findFragmentByTag("rightfragment"));
              ft.commit();
            }
             f = new TableListFragment();
             ft = fm.beginTransaction();
            ft.setCustomAnimations(android.R.anim.fade_in,
                android.R.anim.fade_out);
            ft.add(R.id.rightcontent,f,"rightfragment");
            ft.commit();
            getActivity().findViewById(R.id.btnConfig).setVisibility(View.GONE);
            */}
    });

    btnClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*emp.setKeyValue("server", etServer.getText().toString());
            emp.setKeyValue("password", etPassword.getText().toString());
            emp.commit();
            */
            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft;
            Fragment f = null;
            if (fm.findFragmentByTag("rightfragment") != null) {
                ft = fm.beginTransaction();
                ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
                ft.remove(fm.findFragmentByTag("rightfragment"));
                ft.commit();
            }
            f = new TableListFragment();
            ft = fm.beginTransaction();
            ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
            ft.add(R.id.rightcontent, f, "rightfragment");
            ft.commit();
            getActivity().findViewById(R.id.btnConfig).setVisibility(View.GONE);
        }
    });

    btnSync.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int rbid = rg.getCheckedRadioButtonId();
            pbar.setVisibility(View.VISIBLE);
            new Thread(new syncRun(rbid)).start();
        }
    });

    return v;
}