List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:com.landenlabs.all_devtool.ConsoleFragment.java
@SuppressLint("DefaultLocale") private void updateConsole() { if (mSystemViews.isEmpty()) return;/* w w w .j a v a 2 s . co m*/ try { // ----- System ----- int threadCount = Thread.activeCount(); ApplicationInfo appInfo = getActivity().getApplicationInfo(); mSystemViews.get(SYSTEM_PACKAGE).get(1).setText(appInfo.packageName); mSystemViews.get(SYSTEM_MODEL).get(1).setText(Build.MODEL); mSystemViews.get(SYSTEM_ANDROID).get(1).setText(Build.VERSION.RELEASE); if (Build.VERSION.SDK_INT >= 16) { int lines = 0; final StringBuilder permSb = new StringBuilder(); try { PackageInfo pi = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_PERMISSIONS); for (int i = 0; i < pi.requestedPermissions.length; i++) { if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) { permSb.append(pi.requestedPermissions[i]).append("\n"); lines++; } } } catch (Exception e) { } final int lineCnt = lines; mSystemViews.get(SYSTEM_PERM).get(1).setText(String.format("%d perms [press]", lines)); mSystemViews.get(SYSTEM_PERM).get(1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v.getTag() == null) { String permStr = permSb.toString().replaceAll("android.permission.", "") .replaceAll("\n[^\n]*permission", ""); mSystemViews.get(SYSTEM_PERM).get(1).setText(permStr); mSystemViews.get(SYSTEM_PERM).get(0).setLines(lineCnt); mSystemViews.get(SYSTEM_PERM).get(1).setLines(lineCnt); mSystemViews.get(SYSTEM_PERM).get(1).setTag(lineCnt); } else { mSystemViews.get(SYSTEM_PERM).get(1).setText(String.format("%d perms", lineCnt)); mSystemViews.get(SYSTEM_PERM).get(0).setLines(1); mSystemViews.get(SYSTEM_PERM).get(1).setLines(1); mSystemViews.get(SYSTEM_PERM).get(1).setTag(null); } } }); } else { String permStr = ""; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) permStr += (" Find Loc"); if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) permStr += (" Coarse Loc"); mSystemViews.get(SYSTEM_PERM).get(1).setText(permStr); } ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); int processCnt = actMgr.getRunningAppProcesses().size(); mSystemViews.get(SYSTEM_PROCESSES).get(1).setText(String.format("%d", consoleState.processCnt)); mSystemViews.get(SYSTEM_PROCESSES).get(2).setText(String.format("%d", processCnt)); // mSystemViews.get(SYSTEM_BATTERY).get(1).setText(String.format("%d%%", consoleState.batteryLevel)); mSystemViews.get(SYSTEM_BATTERY).get(2) .setText(String.format("%%%d", calculateBatteryLevel(getActivity()))); // long cpuNano = Debug.threadCpuTimeNanos(); // mSystemViews.get(SYSTEM_CPU).get(2).setText(String.format("%d%%", cpuNano)); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { // ----- Network WiFi----- WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); mNetworkViews.get(NETWORK_WIFI_IP).get(1).setText(Formatter.formatIpAddress(dhcpInfo.ipAddress)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); mNetworkViews.get(NETWORK_WIFI_SPEED).get(1).setText(String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); mNetworkViews.get(NETWORK_WIFI_SIGNAL).get(1) .setText(String.format("%%%d", 100 * level / numberOfLevels)); } } catch (Exception ex) { m_log.e(ex.getMessage()); } try { // ----- Network Traffic----- // int uid = android.os.Process.myUid(); mNetworkViews.get(NETWORK_RCV_BYTES).get(1).setText(String.format("%d", consoleState.netRxBytes)); mNetworkViews.get(NETWORK_RCV_PACK).get(1).setText(String.format("%d", consoleState.netRxPacks)); mNetworkViews.get(NETWORK_SND_BYTES).get(1).setText(String.format("%d", consoleState.netTxBytes)); mNetworkViews.get(NETWORK_SND_PACK).get(1).setText(String.format("%d", consoleState.netTxPacks)); mNetworkViews.get(NETWORK_RCV_BYTES).get(2) .setText(String.format("%d", TrafficStats.getTotalRxBytes())); mNetworkViews.get(NETWORK_RCV_PACK).get(2) .setText(String.format("%d", TrafficStats.getTotalRxPackets())); mNetworkViews.get(NETWORK_SND_BYTES).get(2) .setText(String.format("%d", TrafficStats.getTotalTxBytes())); mNetworkViews.get(NETWORK_SND_PACK).get(2) .setText(String.format("%d", TrafficStats.getTotalRxPackets())); mNetworkViews.get(NETWORK_RCV_BYTES).get(3) .setText(String.format("%d", TrafficStats.getTotalRxBytes() - consoleState.netRxBytes)); mNetworkViews.get(NETWORK_RCV_PACK).get(3) .setText(String.format("%d", TrafficStats.getTotalRxPackets() - consoleState.netRxPacks)); mNetworkViews.get(NETWORK_SND_BYTES).get(3) .setText(String.format("%d", TrafficStats.getTotalTxBytes() - consoleState.netTxBytes)); mNetworkViews.get(NETWORK_SND_PACK).get(3) .setText(String.format("%d", TrafficStats.getTotalRxPackets() - consoleState.netTxPacks)); } catch (Exception ex) { m_log.e(ex.getMessage()); } // ----- Memory ----- try { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long heapUsing = Debug.getNativeHeapSize(); Date now = new Date(); long deltaMsec = now.getTime() - consoleState.lastFreeze.getTime(); List<TextView> timeViews = mMemoryViews.get(MEMORY_TIME); timeViews.get(1).setText(TIMEFORMAT.format(consoleState.lastFreeze)); timeViews.get(2).setText(TIMEFORMAT.format(now)); timeViews.get(3).setText( DateUtils.getRelativeTimeSpanString(consoleState.lastFreeze.getTime(), now.getTime(), 0)); // timeViews.get(3).setText( String.valueOf(deltaMsec)); List<TextView> usingViews = mMemoryViews.get(MEMORY_USING); usingViews.get(1).setText(String.format("%d", consoleState.usingMemory)); usingViews.get(2).setText(String.format("%d", heapUsing)); usingViews.get(3).setText(String.format("%d", heapUsing - consoleState.usingMemory)); List<TextView> freeViews = mMemoryViews.get(MEMORY_FREE); freeViews.get(1).setText(String.format("%d", consoleState.freeMemory)); freeViews.get(2).setText(String.format("%d", mi.availMem)); freeViews.get(3).setText(String.format("%d", mi.availMem - consoleState.freeMemory)); List<TextView> totalViews = mMemoryViews.get(MEMORY_TOTAL); if (Build.VERSION.SDK_INT >= 16) { totalViews.get(1).setText(String.format("%d", consoleState.totalMemory)); totalViews.get(2).setText(String.format("%d", mi.totalMem)); totalViews.get(3).setText(String.format("%d", mi.totalMem - consoleState.totalMemory)); } else { totalViews.get(0).setVisibility(View.GONE); totalViews.get(1).setVisibility(View.GONE); totalViews.get(2).setVisibility(View.GONE); } } catch (Exception ex) { m_log.e(ex.getMessage()); } }
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); }// w w w .j a va2s. c o 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:org.restcomm.app.qoslib.Utils.QosInfo.java
private WifiInfo getWifiInfo() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo; }
From source file:com.xdyou.sanguo.GameSanGuo.java
protected void onCreate(Bundle savedInstanceState) { Log.d("SGAPP", "onCreate"); mActivity = this; super.onCreate(savedInstanceState); //AppsFlyerSDK initial 2015.1.12 AppsFlyerLib.setAppsFlyerKey("6HRzTLQfzQHGBQ87KzZttH"); //? AppsFlyer AppsFlyerLib.sendTracking(getApplicationContext()); //GA sdk ?/*from w w w. ja v a2 s . com*/ GameAnalytics.initialise(this, GA_SCR_KEY, GA_GAME_KEY); GameAnalytics.startSession(this); //MM: AdvertiserSDK 2014.11.26 Tracker.conversionTrack(this, "zywx_sgyxlm_hk_mo_tw"); //?? getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // ========================?TalkingData Log.d("SGAPP", "talkingdataAppid || " + talkingDataAppId); TalkingDataGA.init(this, talkingDataAppId, talkingDataChannelId); // ========================?TalkingData // ===================Facebook ? // ??session this.createFBSession(); // Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); // ===================Facebook ? //GoCPA GocpaUtil.setAppId(GOCPA_APPID); GocpaUtil.setAdvertiserId(GOCPA_ADVID); GocpaUtil.setReferral(false); GocpaTracker.getInstance(this).reportDevice(); // ==================Go2Play listener_Begin_======================================= TradeService.setOnBalanceChangedListener(new ICallback() { @Override public void onResult(boolean isSuccess, Bundle bundle, Throwable ths) { // ??? if (isSuccess) { Log.e("go2play", "Charged Success!"); Log.e("go2play", "Balance: " + TradeService.getBalance(false)); } } }); // ==================Go2Play listener_End_========================================= // ==================ChartBoost SDK _Begin_============================================ // ?chartboost this.cb = Chartboost.sharedChartboost(); // chartboostappIdappKey, sdk???? final String appIdCB = "54af952a43150f627b0fbb4a"; final String appSignatureCB = "bea16683ef974c0393cf55c41719ef694ae8a0d5"; this.cb.onCreate(this, appIdCB, appSignatureCB, null); // ==================ChartBoost SDK_End_============================================== // ==================hasoffers _Begin_============================================ MobileAppTracker.init(getApplicationContext(), "24078", "3fba6dcf91bc7251866e59278574f16a"); mobileAppTracker = MobileAppTracker.getInstance(); // Collect Google Play Advertising ID new Thread(new Runnable() { @Override public void run() { try { Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext()); mobileAppTracker.setGoogleAdvertisingId(adInfo.getId(), adInfo.isLimitAdTrackingEnabled()); } catch (IOException e) { } catch (GooglePlayServicesNotAvailableException e) { mobileAppTracker.setAndroidId(Secure.getString(getContentResolver(), Secure.ANDROID_ID)); } catch (GooglePlayServicesRepairableException e) { // Encountered a recoverable error connecting to Google Play // services. } } }).start(); // For collecting Android ID, device ID, and MAC address // Before August 1st 2014, remove these calls - only Google AID should // be collected. mobileAppTracker.setAndroidId(Secure.getString(getContentResolver(), Secure.ANDROID_ID)); String deviceId = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); mobileAppTracker.setDeviceId(deviceId); try { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); mobileAppTracker.setMacAddress(wm.getConnectionInfo().getMacAddress()); } catch (NullPointerException e) { System.out.println("NullPointerExp"); } // ==================hasoffers _End_=========================== // ?? ?Handler????????facebook? handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case FB_LOGIN: fbLogin(); break; case FB_LOGOUT: fbLogout(); break; case FB_SHARE: { // ????????? String imageName = msg.obj.toString(); fbShareContent(imageName); } break; case FB_CREATE_SESSION: { createFBSession(); } break; case GOTO_GOOGLE_PLAY: { enterGooglePlay(); } break; case BUID_DIALOG: { buildDialog(); } break; case HANDLER_OPEN_URL: { execOpenUrl((String) msg.obj); } break; case APP_FLYERS_LOGIN: { appFlyersTrackerLogin((String) msg.obj); } break; case MSG_SHOW_TOAST: { handleShowToast((String) msg.obj); } break; case MSG_SET_USER_DATA: { handleSetUserData((SgUserData) msg.obj); } break; default: Log.e("facebook", "error come out!"); System.out.println("oh shit!"); break; } } }; }
From source file:org.restcomm.app.qoslib.Utils.QosInfo.java
private WifiConfiguration getWifiConfig() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); WifiConfiguration activeConfig = null; if (wifiManager.getConfiguredNetworks() == null) return null; for (WifiConfiguration conn : wifiManager.getConfiguredNetworks()) { if ((conn.BSSID != null && conn.BSSID.equals(wifiInfo.getBSSID())) || (conn.SSID != null && conn.SSID.equals(wifiInfo.getSSID()))) { activeConfig = conn;//w w w. ja va 2 s. co m break; } } if (activeConfig != null) { return activeConfig; } return null; }
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; }//w w w.ja va2 s .co m } 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);//from www . j a v a 2s. 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.moez.QKSMS.mmssms.Transaction.java
/** * @deprecated/*ww w .j a v a2 s. c o m*/ */ private void revokeWifi(boolean saveState) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (saveState) { settings.currentWifi = wifi.getConnectionInfo(); settings.currentWifiState = wifi.isWifiEnabled(); wifi.disconnect(); settings.discon = new DisconnectWifi(); context.registerReceiver(settings.discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); settings.currentDataState = Utils.isMobileDataEnabled(context); Utils.setMobileDataEnabled(context, true); } else { wifi.disconnect(); wifi.disconnect(); settings.discon = new DisconnectWifi(); context.registerReceiver(settings.discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); Utils.setMobileDataEnabled(context, true); } }
From source file:com.savor.ads.core.Session.java
public String getMacAddr() { if (TextUtils.isEmpty(macAddress)) { try {//from ww w . jav a2s . c om WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); macAddress = info.getMacAddress(); } catch (Exception ex) { LogUtils.e(ex.toString()); } } return macAddress; }
From source file:org.restcomm.app.qoslib.Services.Events.EventManager.java
public WifiInfo getWifiInfo() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo; }