List of usage examples for android.content Context WIFI_SERVICE
String WIFI_SERVICE
To view the source code for android.content Context WIFI_SERVICE.
Click Source Link
From source file:com.xdyou.sanguo.GameSanGuo.java
public static String getMacID() { String str = "mac_address"; WifiManager wifi = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); str = info.getMacAddress();/* w ww .jav a2s . c om*/ // ??imei? if (str == null) { TelephonyManager tm = (TelephonyManager) mActivity.getSystemService(TELEPHONY_SERVICE); str = tm.getDeviceId(); } Log.e("mac_address", str); return str; }
From source file:org.protocoderrunner.apprunner.api.PNetwork.java
@ProtocoderScript @APIMethod(description = "Enable/Disable the Wifi adapter", example = "") @APIParam(params = { "boolean" }) public void enableWifi(boolean enabled) { WifiManager wifiManager = (WifiManager) a.get().getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(enabled); }
From source file:org.protocoderrunner.apprunner.api.PNetwork.java
@ProtocoderScript @APIMethod(description = "Check if the Wifi adapter is enabled", example = "") @APIParam(params = {})//from w w w. j a v a 2s . com public boolean isWifiEnabled() { WifiManager wifiManager = (WifiManager) a.get().getSystemService(Context.WIFI_SERVICE); return wifiManager.isWifiEnabled(); }
From source file:org.protocoderrunner.apprunner.api.PNetwork.java
@ProtocoderScript @APIMethod(description = "Connect to a given Wifi network with a given 'wpa', 'wep', 'open' type and a password", example = "") @APIParam(params = { "ssidName", "type", "password" }) public void connectWifi(String networkSSID, String type, String networkPass) { WifiConfiguration conf = new WifiConfiguration(); conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String // should contain ssid in quotes if (type.equals("wep")) { // wep/*from w ww.j a v a 2 s. c o m*/ conf.wepKeys[0] = "\"" + networkPass + "\""; conf.wepTxKeyIndex = 0; conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); } else if (type.equals("wpa")) { // wpa conf.preSharedKey = "\"" + networkPass + "\""; } else if (type.equals("open")) { // open conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); } WifiManager wifiManager = (WifiManager) a.get().getSystemService(Context.WIFI_SERVICE); wifiManager.addNetwork(conf); List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for (WifiConfiguration i : list) { if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) { wifiManager.disconnect(); wifiManager.enableNetwork(i.networkId, true); wifiManager.reconnect(); break; } } }
From source file:github.daneren2005.dsub.util.Util.java
public static String getSSID(Context context) { if (isWifiConnected(context)) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getSSID() != null) { return wifiManager.getConnectionInfo().getSSID().replace("\"", ""); }//from www.j a va 2s . co m return null; } return null; }
From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java
private void displayIpAddress() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); if (info != null && info.getNetworkId() > -1) { int i = info.getIpAddress(); String ip = String.format("%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff, i >> 24 & 0xff); line1.setText("HTTP://"); line1.append(ip);/* w w w . j a v a 2 s.co m*/ line1.append(":8080"); line2.setText("RTSP://"); line2.append(ip); line2.append(":8086"); streamingState(0); } else { line1.setText("HTTP://xxx.xxx.xxx.xxx:8080"); line2.setText("RTSP://xxx.xxx.xxx.xxx:8086"); streamingState(2); } }
From source file:com.nbplus.iotapp.service.IoTService.java
@Override public void onCreate() { Log.i(TAG, "debug: Creating service"); sendBroadcast(new Intent(IoTConstants.ACTION_SERVICE_CREATE_BROADCAST)); /**//from w ww . j a va 2s. c om * Target we publish for clients to send messages to IncomingHandler.Note * that calls to its binder are sequential! */ mServiceMessenger = new Messenger(mHandler); mUseIoTGateway = IoTServicePreference.isUseIoTGateway(this); if (mUseIoTGateway) { Log.d(TAG, ">> Use IoT Gateway...."); // Create the Wifi lock (this does not acquire the lock, this just creates it) mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, IoTService.class.getSimpleName() + "_lock"); // check network status IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mBroadcastReceiver, intentFilter); mLastConnectionStatus = NetworkUtils.isConnected(this); // TODO : connect to iot gateway if (mThreadPooledServer != null) { mThreadPooledServer.stop(false); } mThreadPooledServer = new ThreadPooledServer(mServiceMessenger, IoTConstants.IOT_GATEWAY_SERVER_PORT, IoTConstants.IOT_GATEWAY_SERVER_THREAD_POOL_SIZE); new Thread(mThreadPooledServer).start(); } else { Log.d(TAG, ">> Use internal blutooth...."); // check bluetooth status IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(mBroadcastReceiver, intentFilter); // bluetooth local broadcast intentFilter = makeGattUpdateIntentFilter(); LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter); // connect to ble service mErrorCodes = checkBluetoothEnabled(); if (mErrorCodes.equals(IoTResultCodes.SUCCESS)) { try { if (mBluetoothServiceConnection != null) { unbindService(mBluetoothServiceConnection); } } catch (Exception e) { } final Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); bindService(gattServiceIntent, mBluetoothServiceConnection, BIND_AUTO_CREATE); } else { mServiceStatus = IoTServiceStatus.STOPPED; Log.d(TAG, "Internal bluetooth error = " + mErrorCodes); } } }
From source file:github.daneren2005.dsub.util.Util.java
public static WifiManager.WifiLock createWifiLock(Context context, String tag) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int lockType = WifiManager.WIFI_MODE_FULL; if (Build.VERSION.SDK_INT >= 12) { lockType = 3;// ww w . j a v a2 s .c om } return wm.createWifiLock(lockType, tag); }
From source file:com.vonglasow.michael.satstat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); File dumpFile = new File(dumpDir, "satstat-" + System.currentTimeMillis() + ".log"); PrintStream s;//from ww w .jav a 2 s. c o m try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); final ActionBar actionBar = getActionBar(); setContentView(R.layout.activity_main); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d("MainActivity", "isWideScreen=" + Boolean.toString(isWideScreen)); // compact action bar int dpX = (int) (this.getResources().getDisplayMetrics().widthPixels / this.getResources().getDisplayMetrics().density); /* * This is a crude way to ensure a one-line action bar with tabs * (not a drop-down list) and home (incon) and title only if there * is space, depending on screen width: * divide screen in units of 64 dp * each tab requires 1 unit, home and menu require slightly less, * title takes up approx. 2.5 units in portrait, * home and title are about 2 units wide in landscape */ if (dpX < 192) { // just enough space for drop-down list and menu actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 320) { // not enough space for four tabs, but home will fit next to list actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 384) { // just enough space for four tabs actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if ((dpX < 448) || ((config.orientation == Configuration.ORIENTATION_PORTRAIT) && (dpX < 544))) { // space for four tabs and home, but not title actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else { // ample space for home, title and all four tabs actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(true); } setEmbeddedTabs(actionBar, true); providerLocations = new HashMap<String, Location>(); mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(LOCATION_PROVIDER_STYLES)); providerStyles = new HashMap<String, String>(); providerAppliedStyles = new HashMap<String, String>(); providerInvalidationHandler = new Handler(); providerInvalidators = new HashMap<String, Runnable>(); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(this); // Add tabs, specifying the tab's text and TabListener for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab() //.setText(mSectionsPagerAdapter.getPageTitle(i)) .setIcon(mSectionsPagerAdapter.getPageIcon(i)).setTabListener(this)); } // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes); mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes); mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes); mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes); mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes); mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes); mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes); mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes); networkTimehandler = new Handler(); networkTimeRunnable = new Runnable() { @Override public void run() { int newNetworkType = mTelephonyManager.getNetworkType(); if (getNetworkGeneration(newNetworkType) != mLastNetworkGen) onNetworkTypeChanged(newNetworkType); else networkTimehandler.postDelayed(this, NETWORK_REFRESH_DELAY); } }; wifiTimehandler = new Handler(); wifiTimeRunnable = new Runnable() { @Override public void run() { mWifiManager.startScan(); wifiTimehandler.postDelayed(this, WIFI_REFRESH_DELAY); } }; updateLocationProviderStyles(); }
From source file:com.example.aaron.test.MyGLSurfaceView.java
public WifiInfo getWifi(Context context) { WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (manager.isWifiEnabled()) { WifiInfo wifiInfo = manager.getConnectionInfo(); if (wifiInfo != null) { return wifiInfo; }/*from w w w .j av a2 s.c om*/ } return null; }