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:de.schildbach.litecoinwallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, lockName);
    wifiLock.setReferenceCounted(false);

    application = (WalletApplication) getApplication();
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0);

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);/*from  w w  w  . j  a  v  a2s  .c  o  m*/

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting litecoinwallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();

        if (!blockChainFileExists && earliestKeyCreationTime > 0) {
            try {
                final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME);
                CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                        earliestKeyCreationTime);
            } catch (final IOException x) {
                log.error("problem reading checkpoints, continuing without", x);
            }
        }
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}

From source file:com.mobilyzer.util.PhoneUtils.java

public String getWifiSSID() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null) {
        return wifiInfo.getSSID();
    }/*w  ww .  j ava  2s .  c o m*/
    return null;
}

From source file:com.wbtech.ums.UmsAgent.java

private static JSONObject getClientDataJSONObject(Context context) {
    TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE));
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics displaysMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(displaysMetrics);
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    JSONObject clientData = new JSONObject();
    try {//from w  w  w  .  jav  a  2 s  . c  o m
        clientData.put("os_version", CommonUtil.getOsVersion(context));
        clientData.put("platform", "android");
        clientData.put("language", Locale.getDefault().getLanguage());
        clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());//
        clientData.put("appkey", CommonUtil.getAppKey(context));
        clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels);
        clientData.put("ismobiledevice", true);
        clientData.put("phonetype", tm.getPhoneType());//
        clientData.put("imsi", tm.getSubscriberId());
        clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context));
        clientData.put("time", CommonUtil.getTime());
        clientData.put("version", CommonUtil.getVersion(context));
        clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context));

        SCell sCell = CommonUtil.getCellInfo(context);

        clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : "");
        clientData.put("cellid", sCell != null ? sCell.CID + "" : "");
        clientData.put("lac", sCell != null ? sCell.LAC + "" : "");
        clientData.put("modulename", Build.PRODUCT);
        clientData.put("devicename", CommonUtil.getDeviceName());
        clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress());
        clientData.put("havebt", adapter == null ? false : true);
        clientData.put("havewifi", CommonUtil.isWiFiActive(context));
        clientData.put("havegps", locationManager == null ? false : true);
        clientData.put("havegravity", CommonUtil.isHaveGravity(context));//

        LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context,
                UmsAgent.mUseLocationService);
        clientData.put("latitude", coordinates.latitude);
        clientData.put("longitude", coordinates.longitude);
        CommonUtil.printLog("clientData---------->", clientData.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return clientData;
}

From source file:com.google.android.apps.tvremote.DeviceFinder.java

private InetAddress getBroadcastAddress() throws IOException {
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();/*from  w  ww.  j  a v a 2 s  . c  om*/
    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++) {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }
    return InetAddress.getByAddress(quads);
}

From source file:org.droidpres.activity.TransferActivity.java

private WifiManager getWiFiManager() {
    if (mWiFiManager == null) {
        mWiFiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    }
    return mWiFiManager;
}

From source file:com.mobilyzer.util.PhoneUtils.java

public String getWifiIpAddress() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null) {
        int ip = wifiInfo.getIpAddress();
        if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
            ip = Integer.reverseBytes(ip);
        }//from   w w w  .j ava  2s . co  m
        byte[] bytes = BigInteger.valueOf(ip).toByteArray();
        String address;
        try {
            address = InetAddress.getByAddress(bytes).getHostAddress();
            return address;
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }
    return null;
}

From source file:xj.property.ums.UmsAgent.java

public static JSONObject getClientDataJSONObject(Context context) {
    TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE));
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics displaysMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(displaysMetrics);
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    JSONObject clientData = new JSONObject();
    try {//  w  ww.j a va 2s  .  c  o m
        clientData.put("os_version", CommonUtil.getOsVersion(context));
        clientData.put("platform", "android");
        clientData.put("language", Locale.getDefault().getLanguage());
        clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());//
        clientData.put("appkey", CommonUtil.getAppKey(context));
        clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels);
        clientData.put("ismobiledevice", true);
        clientData.put("phonetype", tm.getPhoneType());//
        clientData.put("imsi", tm.getSubscriberId());
        clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context));
        clientData.put("time", CommonUtil.getTime());
        clientData.put("version", CommonUtil.getVersion(context));
        clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context));

        SCell sCell = CommonUtil.getCellInfo(context);

        clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : "");
        clientData.put("cellid", sCell != null ? sCell.CID + "" : "");
        clientData.put("lac", sCell != null ? sCell.LAC + "" : "");
        clientData.put("modulename", Build.PRODUCT);
        clientData.put("devicename", CommonUtil.getDeviceName());
        clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress());
        clientData.put("havebt", adapter == null ? false : true);
        clientData.put("havewifi", CommonUtil.isWiFiActive(context));
        clientData.put("havegps", locationManager == null ? false : true);
        clientData.put("havegravity", CommonUtil.isHaveGravity(context));//

        LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context,
                UmsAgent.mUseLocationService);
        clientData.put("latitude", coordinates.latitude);
        clientData.put("longitude", coordinates.longitude);
        CommonUtil.printLog("clientData---------->", clientData.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return clientData;
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshWifiStatus(Context context, RemoteViews widget) {
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int wifiStatus = mWifiManager.getWifiState();
    if (WifiManager.WIFI_STATE_ENABLED == wifiStatus || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
        widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
    } else {//  w w w .  j  av  a  2 s. co m
        widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
    }
}

From source file:com.github.jthuraisamy.yellowusage.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set app bar.
    Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(appBar);// w  ww  .j av a 2s .c o m

    // Instantiate managers.
    connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    networkBrand = telephonyManager.getNetworkOperatorName();

    // Get objects in the data usage card.
    dataUsageCard = (CardView) findViewById(R.id.cardView_dataUsage);
    dataUsagePrimarySubheader = (TextView) findViewById(R.id.textView_dataUsagePrimarySubheader);
    dataUsagePrimaryValue = (TextView) findViewById(R.id.textView_dataUsagePrimaryValue);
    dataUsageSecondaryValue = (TextView) findViewById(R.id.textView_dataUsageSecondaryValue);
    dataUsageProgress = (ProgressBar) findViewById(R.id.progressBar_dataUsage);
    dataProtectionSwitch = (Switch) findViewById(R.id.switch_dataProtection);

    // Get objects in the voice usage card.
    voiceUsageCard = (CardView) findViewById(R.id.cardView_voiceUsage);
    voiceUsagePrimarySubheader = (TextView) findViewById(R.id.textView_voiceUsagePrimarySubheader);
    voiceUsagePrimaryValue = (TextView) findViewById(R.id.textView_voiceUsagePrimaryValue);
    voiceUsageSecondaryValue = (TextView) findViewById(R.id.textView_voiceUsageSecondaryValue);
    voiceUsageProgress = (ProgressBar) findViewById(R.id.progressBar_voiceUsage);
    voiceProtectionSwitch = (Switch) findViewById(R.id.switch_voiceProtection);

    // Get objects in the messaging usage card.
    messagingUsageCard = (CardView) findViewById(R.id.cardView_messagingUsage);
    messagingUsagePrimarySubheader = (TextView) findViewById(R.id.textView_messagingUsagePrimarySubheader);
    messagingUsagePrimaryValue = (TextView) findViewById(R.id.textView_messagingUsagePrimaryValue);
    messagingUsageSecondaryValue = (TextView) findViewById(R.id.textView_messagingUsageSecondaryValue);
    messagingUsageProgress = (ProgressBar) findViewById(R.id.progressBar_messagingUsage);
    messagingProtectionSwitch = (Switch) findViewById(R.id.switch_messagingProtection);

    // Get objects in the sliding panel layout.
    feesPanel = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    bottomBar = (Toolbar) findViewById(R.id.bottom_bar);
    overageStatus = (TextView) findViewById(R.id.textView_overageStatus);
    planNameHeader = (TextView) findViewById(R.id.textView_planNameHeader);
    totalAmountDueValue = (TextView) findViewById(R.id.textView_totalAmountDueValue);
    paymentDueDateValue = (TextView) findViewById(R.id.textView_paymentDueDateValue);
    nextBillDateValue = (TextView) findViewById(R.id.textView_nextBillDateValue);
    dataOverageFeesValue = (TextView) findViewById(R.id.textView_dataOverageFeesValue);
    weekdayMinutesOverageFeesValue = (TextView) findViewById(R.id.textView_weekdayMinutesOverageFeesValue);

    // Instantiate Realm.
    realm = Realm.getInstance(this);

    // Register broadcast receiver for UI refreshes.
    LocalBroadcastManager.getInstance(this).registerReceiver(uiRefreshReceiver,
            new IntentFilter(Constants.ACTION_REFRESH_UI_SECTION));
    LocalBroadcastManager.getInstance(this).registerReceiver(asyncTaskReceiver,
            new IntentFilter(Constants.ACTION_ASYNC_TASK));

    // Check if the user is connected to the right network.
    if (!isConnectedNetworkOperatorValid(telephonyManager) && !isAirplaneModeOn(this)) {
        InvalidNetworkDialog invalidNetworkDialog = InvalidNetworkDialog
                .create(telephonyManager.getNetworkOperatorName());
        invalidNetworkDialog.show(getSupportFragmentManager(), InvalidNetworkDialog.TAG);
    } else {
        // Refresh UI with the most recent cached information.
        startActionRefreshUI(this);
    }
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

public static String getHWID(Context cx) {
    if (sHWID != null)
        return sHWID;

    // If we're on SDK version > 8, use Build.SERIAL
    if (android.os.Build.VERSION.SDK_INT > 8) {
        sHWID = android.os.Build.SERIAL;
    }// ww w  .ja v  a  2s  .c o  m

    if (sHWID != null)
        return sHWID;

    // Otherwise, try from the telephony manager
    TelephonyManager mTelephonyMgr = (TelephonyManager) cx.getSystemService(TELEPHONY_SERVICE);
    if (mTelephonyMgr != null) {
        sHWID = mTelephonyMgr.getDeviceId();
    }

    if (sHWID != null)
        return sHWID;

    // Otherwise, try WIFI_SERVICE and use the wifi manager
    WifiManager wifiMan = (WifiManager) cx.getSystemService(Context.WIFI_SERVICE);
    if (wifiMan != null) {
        WifiInfo wifi = wifiMan.getConnectionInfo();
        if (wifi != null) {
            sHWID = "wifimac" + wifi.getMacAddress();
        }
    }

    if (sHWID != null)
        return sHWID;

    sHWID = "0011223344556677";

    return sHWID;
}