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:com.davidmascharka.lips.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestMyPermissions();/*from  w w  w  .jav  a 2 s . c  o m*/
    }

    getPreferences();

    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new MainFragment()).commit();
    }

    rotation = new float[9];
    inclination = new float[9];
    orientation = new float[3];

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationListener = new LocationListener() {

        @Override
        public void onLocationChanged(Location location) {
            updateLocation(location);
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }
    };

    wifiReadings = new LinkedHashMap<String, Integer>();
    resetWifiReadings(building);

    userInitiatedScan = false;
}

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING:/*ww  w  . ja  va2 s .com*/
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.eurotong.orderhelperandroid.Common.java

public static String GetWifiMacAddress() {
    String id = "UNKNOWN";
    Object idObject = null;/*  w  w w  .  j a  v a 2 s.c  om*/
    WifiManager wifiMan = (WifiManager) MyApplication.getAppContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInf = wifiMan.getConnectionInfo();
    String macAddr = wifiInf.getMacAddress();
    id = macAddr;
    return id;
}

From source file:org.allseen.lsf.sampleapp.view.MainFragment.java

protected boolean isWifiConnected() {
    NetworkInfo wifiNetworkInfo = ((ConnectivityManager) getActivity()
            .getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    // determine if wifi AP mode is on
    boolean isWifiApEnabled = false;
    WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    // need reflection because wifi ap is not in the public API
    try {/*  w w  w.j a  v  a  2  s.c  om*/
        Method isWifiApEnabledMethod = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled");
        isWifiApEnabled = (Boolean) isWifiApEnabledMethod.invoke(wifiManager);
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Log.d(SampleAppActivity.TAG, "Connectivity state " + wifiNetworkInfo.getState().name() + " - connected:" + wifiNetworkInfo.isConnected() + " hotspot:" + isWifiApEnabled);

    return wifiNetworkInfo.isConnected() || isWifiApEnabled;
}

From source file:com.google.appinventor.components.runtime.BlockyTalky.java

private void aquireMulticastLock() {
    WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    if (wifi != null) {
        WifiManager.MulticastLock lock = wifi.createMulticastLock(LOG_TAG);
        lock.acquire();/* www.j a  va  2s  . c  om*/
    } else {
        Log.d(LOG_TAG, "WIFI MANAGER NULL");
    }
}

From source file:in.neoandroid.neoupdate.neoUpdate.java

public static String getWifiMac(Context c) {
    try {//from  w  ww.  java  2s . co  m
        WifiManager wifiMgr = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        return wifiMgr.getConnectionInfo().getMacAddress();
    } catch (Exception e) {
    }
    return null;
}

From source file:ca.frozen.curlingtv.classes.Utils.java

public static String getWifiName() {
    String ssid = "";
    WifiManager manager = (WifiManager) App.getContext().getSystemService(Context.WIFI_SERVICE);
    if (manager.isWifiEnabled()) {
        WifiInfo wifiInfo = manager.getConnectionInfo();
        if (wifiInfo != null) {
            NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
            if (state == NetworkInfo.DetailedState.CONNECTED
                    || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
                ssid = wifiInfo.getSSID();
                if (ssid == null)
                    ssid = "";
                ssid = ssid.replaceAll("^\"|\"$", "");
            }// www  .ja v  a  2  s  .  c  o m
        }
    }
    return ssid;
}

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.HandsetFragment.java

private void displayIpAddress() {
    WifiManager wifiManager = (WifiManager) mApplication.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    String ipaddress = null;/* ww w  .j  ava  2s .  c o  m*/
    if (info != null && info.getNetworkId() > -1) {
        int i = info.getIpAddress();
        String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff,
                i >> 24 & 0xff);
        mLine1.setText(mHttpServer.isHttpsEnabled() ? "https://" : "http://");
        mLine1.append(ip);
        mLine1.append(":" + mHttpServer.getHttpPort());
        mLine2.setText("rtsp://");
        mLine2.append(ip);
        mLine2.append(":" + mRtspServer.getPort());
        streamingState(0);
    } else if ((ipaddress = Utilities.getLocalIpAddress(true)) != null) {
        mLine1.setText(mHttpServer.isHttpsEnabled() ? "https://" : "http://");
        mLine1.append(ipaddress);
        mLine1.append(":" + mHttpServer.getHttpPort());
        mLine2.setText("rtsp://");
        mLine2.append(ipaddress);
        mLine2.append(":" + mRtspServer.getPort());
        streamingState(0);
    } else {
        streamingState(2);
    }

}

From source file:fm.feed.android.testapp.fragment.TestFragment.java

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

    mBtnTune.setOnClickListener(tune);/*from w w w .ja v  a 2  s.  c o m*/
    mBtnPlay.setOnClickListener(play);
    mBtnPause.setOnClickListener(pause);
    mBtnSkip.setOnClickListener(skip);
    mBtnLike.setOnClickListener(like);
    mBtnUnlike.setOnClickListener(unlike);
    mBtnDislike.setOnClickListener(dislike);
    mBtnHistory.setOnClickListener(history);

    mPlacementsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mStationsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    mBtnToggleWifi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ConnectivityManager cm = (ConnectivityManager) getActivity()
                    .getSystemService(Context.CONNECTIVITY_SERVICE);

            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

            WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
            wifi.setWifiEnabled(!isConnected); // true or false to activate/deactivate wifi

            mBtnToggleWifi.setText(!isConnected ? "Wifi ON" : "Wifi OFF");
        }
    });

    List<HashMap<String, Integer>> fillMaps = new ArrayList<HashMap<String, Integer>>();
    for (Integer p : mPlacements) {
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        map.put("Placement", p);
        fillMaps.add(map);
    }

    final SimpleAdapter adapter = new SimpleAdapter(getActivity(), fillMaps,
            android.R.layout.simple_list_item_1, new String[] { "Placement" },
            new int[] { android.R.id.text1 });
    mPlacementsView.setAdapter(adapter);
    mPlacementsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mSelectedPlacementsIndex = position;

            HashMap<String, Integer> item = (HashMap<String, Integer>) adapter.getItem(position);
            Integer placementId = item.get("Placement");
            Toast.makeText(getActivity(), placementId.toString(), Toast.LENGTH_LONG).show();
            mPlayer.setPlacementId(placementId);

        }
    });

    resetTrackInfo();

    if (mPlayer.hasPlay()) {
        updateTrackInfo(mPlayer.getPlay());
    }
    if (mPlayer.hasStationList()) {
        updateStations(mPlayer.getStationList());
    }
}

From source file:com.laer.easycast.ImagePane.java

public void photoRaw(Bitmap image, String transition) {

    Log.i("photoraw", "photoraw called");

    headers.put("X-Apple-Transition", transition);

    image.compress(Bitmap.CompressFormat.JPEG, 100, wr);
    MainActivity obj = (MainActivity) getActivity();
    WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    if (obj.URL != null) {
        new PhotoAirplay().execute();
    } else if (obj.URL == null && !wifi.isWifiEnabled()) {
        WiFiOptions();//from w  w w. j  av  a  2  s. c  om

        if (obj.URL == null) {
            Toast.makeText(getActivity(), "No compatible devices found", Toast.LENGTH_SHORT).show();
        }

    }

}