List of usage examples for android.telephony TelephonyManager getLine1Number
@SuppressAutoDoc
@RequiresPermission(anyOf = { android.Manifest.permission.READ_PHONE_STATE,
android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS })
public String getLine1Number()
From source file:com.framgia.android.emulator.EmulatorDetector.java
private boolean checkPhoneNumber() { TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); @SuppressLint("HardwareIds") String phoneNumber = telephonyManager.getLine1Number(); for (String number : PHONE_NUMBERS) { if (number.equalsIgnoreCase(phoneNumber)) { log(" check phone number is detected"); return true; }/* ww w . java 2 s . c o m*/ } return false; }
From source file:com.example.android.bluetoothchat.BluetoothFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);//from ww w . ja v a2 s . c o m // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { FragmentActivity activity = getActivity(); Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show(); activity.finish(); } TelephonyManager telManager = (TelephonyManager) getActivity() .getSystemService(getActivity().TELEPHONY_SERVICE); phoneNum = telManager.getLine1Number(); }
From source file:RhodesService.java
public static Object getProperty(String name) { try {// w w w . j a va2 s . c o m if (name.equalsIgnoreCase("platform")) return "ANDROID"; else if (name.equalsIgnoreCase("locale")) return getCurrentLocale(); else if (name.equalsIgnoreCase("country")) return getCurrentCountry(); else if (name.equalsIgnoreCase("screen_width")) return Integer.valueOf(getScreenWidth()); else if (name.equalsIgnoreCase("screen_height")) return Integer.valueOf(getScreenHeight()); else if (name.equalsIgnoreCase("screen_orientation")) { int orientation = getScreenOrientation(); if ((orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) || (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)) return "landscape"; else return "portrait"; } else if (name.equalsIgnoreCase("has_network")) return Boolean.valueOf(hasNetwork()); else if (name.equalsIgnoreCase("has_wifi_network")) return Boolean.valueOf(hasWiFiNetwork()); else if (name.equalsIgnoreCase("has_cell_network")) return Boolean.valueOf(hasCellNetwork()); else if (name.equalsIgnoreCase("ppi_x")) return Float.valueOf(getScreenPpiX()); else if (name.equalsIgnoreCase("ppi_y")) return Float.valueOf(getScreenPpiY()); else if (name.equalsIgnoreCase("phone_number")) { Context context = ContextFactory.getContext(); String number = ""; if (context != null) { TelephonyManager manager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); number = manager.getLine1Number(); Logger.I(TAG, "Phone number: " + number + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); } return number; } else if (name.equalsIgnoreCase("device_owner_name")) { return AndroidFunctionalityManager.getAndroidFunctionality() .AccessOwnerInfo_getUsername(getContext()); } else if (name.equalsIgnoreCase("device_owner_email")) { return AndroidFunctionalityManager.getAndroidFunctionality().AccessOwnerInfo_getEmail(getContext()); } else if (name.equalsIgnoreCase("device_name")) { return Build.MANUFACTURER + " " + Build.DEVICE; } else if (name.equalsIgnoreCase("is_emulator")) { String strDevice = Build.DEVICE; return Boolean.valueOf(strDevice != null && strDevice.equalsIgnoreCase("generic")); } else if (name.equalsIgnoreCase("os_version")) { return Build.VERSION.RELEASE; } else if (name.equalsIgnoreCase("has_calendar")) { return Boolean.valueOf(EventStore.hasCalendar()); } else if (name.equalsIgnoreCase("phone_id")) { RhodesService service = RhodesService.getInstance(); if (service != null) { PhoneId phoneId = service.getPhoneId(); return phoneId.toString(); } else { return ""; } } else if (name.equalsIgnoreCase("webview_framework")) { return RhodesActivity.safeGetInstance().getMainView().getWebView(-1).getEngineId(); } else if (name.equalsIgnoreCase("is_motorola_device")) { return isMotorolaDevice(); } else if (name.equalsIgnoreCase("oem_info")) { return Build.PRODUCT; } else if (name.equalsIgnoreCase("uuid")) { return fetchUUID(); } else if (name.equalsIgnoreCase("has_camera")) { return Boolean.TRUE; } else { return RhoExtManager.getImplementationInstance().getProperty(name); } } catch (Exception e) { Logger.E(TAG, "Can't get property \"" + name + "\": " + e); } return null; }
From source file:com.supremainc.biostar2.door.DoorFragment.java
private void sendOpenRequest() { String PhoneNumber = null;//from w w w . j a v a 2s . co m try { if (Build.VERSION.SDK_INT >= 23) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(mContext, new String[] { Manifest.permission.READ_PHONE_STATE }, Setting.REQUEST_READ_PHONE_STATE); return; } } TelephonyManager telephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); if (telephony != null) { PhoneNumber = telephony.getLine1Number(); } if (PhoneNumber != null) { PhoneNumber = PhoneNumberUtils.formatNumber(PhoneNumber); } } catch (Exception e) { PhoneNumber = null; if (BuildConfig.DEBUG) { Log.e(TAG, " " + e.getMessage()); } } if (PhoneNumber == null) { PhoneNumber = mDoorDataProvider.getLoginUserInfo().phone_number; } mPopup.showWait(true); mDoorDataProvider.openRequestDoor(TAG, mDoor.id, PhoneNumber, mRequestDoorListener, mRequestDoorErrorListener, null); }
From source file:com.mcnc.parecis.bizmob.task.Login20Task.java
@Override protected Response doInBackground(Object... arg0) { Response response = new Response(); final Request request = getRequest(); final BaseActivity activity = request.getSrcActivity(); String callback = ""; String legacy_trcode = ""; JSONObject root = null;/*from w w w. ja v a 2s . c o m*/ JSONObject param = null; JSONObject auth_info = null; JSONObject legacy_message = null; String progressMsg = ""; ConfigurationModel cm = ConfigurationModel.getConfigurationModel(); long start = System.currentTimeMillis(); try { Logger.d(TAG, "doInBackground"); root = (JSONObject) request.getData(); param = root.getJSONObject("param"); // if (param.has("progress_message")) { progressMsg = param.getString("progress_message"); AbstractActivity.PROGRESS_MESSAGE = progressMsg; activity.runOnUiThread(new Runnable() { @Override public void run() { if (activity.getDlg() != null) { activity.getDlg().setMessage(AbstractActivity.PROGRESS_MESSAGE); } } }); } callback = param.getString("callback"); // ?? . //message = param.getJSONObject("message"); auth_info = param.getJSONObject("auth_info"); legacy_trcode = param.getString("legacy_trcode"); legacy_message = param.getJSONObject("legacy_message"); String password = ""; String user_id = ""; password = auth_info.getString("password"); user_id = auth_info.getString("user_id"); JSONObject data = new JSONObject(); JSONObject newParam = new JSONObject(); JSONObject newMassage = new JSONObject(); JSONObject newHeader = new JSONObject(); JSONObject newBody = new JSONObject(); data.put("param", newParam); newParam.put("message", newMassage); newMassage.put("header", newHeader); newMassage.put("body", newBody); newHeader.put("result", true); newHeader.put("error_code", ""); newHeader.put("error_text", ""); newHeader.put("info_text", ""); newHeader.put("message_version", "0.9"); newHeader.put("login_session_id", ""); newHeader.put("trcode", "LOGIN"); newBody.put("password", password); newBody.put("legacy_trcode", legacy_trcode); newBody.put("legacy_message", legacy_message); newBody.put("user_id", user_id); newBody.put("os_type", Def.OS_TYPE_NAME); boolean emulFlag = false; if (android.os.Build.MODEL.contains("sdk")) { emulFlag = true; } TelephonyManager manager = (TelephonyManager) request.getSrcActivity() .getSystemService(Context.TELEPHONY_SERVICE); boolean manual_phone_number = false; String mobilenum = ""; String tempNumber = ""; if (manager != null) { tempNumber = manager.getLine1Number(); if (tempNumber == null) { mobilenum = cm.getStringSharedPreferences("MANUAL_NUMBER"); manual_phone_number = true; } else if (tempNumber.equals("")) { manual_phone_number = true; mobilenum = cm.getStringSharedPreferences("MANUAL_NUMBER"); } else { if (emulFlag == true) { manual_phone_number = true; mobilenum = cm.getStringSharedPreferences("MANUAL_NUMBER"); } else { manual_phone_number = false; mobilenum = tempNumber; } } } else { mobilenum = cm.getStringSharedPreferences("MANUAL_NUMBER"); if (mobilenum.equals(ConfigurationModel.PREFERENCE_NOTFOUND)) { mobilenum = ""; } manual_phone_number = true; } String device_id = ""; if (manager != null) { device_id = manager.getDeviceId(); if (device_id == null) { device_id = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID); } } else { device_id = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID); } newBody.put("manual_phone_number", manual_phone_number); newBody.put("device_id", device_id); // emulator flag true ? device? ? if (auth_info.has("emulator_flag")) { newBody.put("emulator_flag", auth_info.getBoolean("emulator_flag")); } else { newBody.put("emulator_flag", emulFlag); } newBody.put("app_key", Def.APPLICTION_NAME); newBody.put("phone_number", mobilenum); request.setData(data); request.setTrCode("LOGIN"); response.setCallback(callback); JSONObject result = sendReq(request); JSONObject header = null; JSONObject body = null; if (result.has("header")) { header = result.getJSONObject("header"); } boolean remote = false; boolean access_limit = false; if (header.getBoolean("result")) { if (result.has("body")) { body = result.getJSONObject("body"); } // License ? Login20Task SUCCESS ? ?? Task ? ??? // License ?? ? String device_type = cm.getStringSharedPreferences("device_type"); Def.LICENSE_NO_VALUE = body.getString("license_no"); Def.USER_TYPE_VALUE = body.getString("user_type"); //ActivationTask? ? ? ?? Def.DEVICE_TYPE_VALUE = device_type; Def.USER_ID_VALUE = user_id; Def.DEVICE_ID_VALUE = device_id; Def.COMPANY_ID_VALUE = body.getString("company_id"); //"attachment_download": true, //"access_limit": false, //"legacy_message": "", //"legacy_trcode": "" // App Tester boolean app_tester = body.getBoolean("app_tester"); boolean app_tester_before = cm.getBooleanSharedPreferences(ConfigurationModel.APP_TESTER); // Update ? ? ? ? ??. if (app_tester != app_tester_before) { String CONTENT_ROOT = ImageUtil.ROOT_PATH + ImageUtil.CONTENT_ROOT + "/"; activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, "?? .", Toast.LENGTH_LONG).show(); } }); File f = new File(CONTENT_ROOT); if (f.exists()) { FileUtils.delete(f); } cm.setBooleanSharedPreferences(ConfigurationModel.APP_TESTER, app_tester); cm.setVersionContentMajor(0); cm.setVersionContentMinor(0); activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, MSG_CHANGE_USER_TYPE, Toast.LENGTH_LONG).show(); } }); activity.finish(); return null; } // remote wipe remote = body.getBoolean("remote_wipe"); if (remote) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, MSG_REMOTEWPE, Toast.LENGTH_LONG).show(); } }); activity.finish(); return null; } // assess limmit access_limit = body.getBoolean("access_limit"); if (access_limit) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, MSG_ACCESS_LIMIIT, Toast.LENGTH_LONG).show(); } }); activity.finish(); return null; } JSONObject reust_legacy_message = body.getJSONObject("legacy_message"); response.setData(reust_legacy_message); } else { Logger.d(TAG, "bizMob result false : " + result); response.setError(false); response.setData(result); } } catch (Exception e) { e.printStackTrace(); Logger.d(TAG, "Send Error : " + e.getMessage()); JSONObject root1 = new JSONObject(); JSONObject header = new JSONObject(); try { root1.put("header", header); header.put("result", false); if (e instanceof HttpResponseException) { // HTTTP header.put("error_code", "HTTP" + ((HttpResponseException) e).getStatusCode()); header.put("error_text", e.getMessage()); } else if (e instanceof HttpHostConnectException) { // Connect header.put("error_code", "NE0001"); header.put("error_text", e.getMessage()); } else if (e instanceof ConnectTimeoutException) { // Connect header.put("error_code", "NE0001"); header.put("error_text", e.getMessage()); } else if (e instanceof SocketTimeoutException) { // Read header.put("error_code", "NE0002"); header.put("error_text", e.getMessage()); } else if (e instanceof IOException) { // ? ? ? header.put("error_code", "NE0003"); header.put("error_text", e.getMessage()); } else if (e instanceof NullPointerException) { header.put("error_code", "CE0001"); // ? ? header.put("error_text", "NullPointerException"); } else { header.put("error_code", "CE0001"); // ? ? header.put("error_text", e.getMessage()); } } catch (JSONException e1) { e1.printStackTrace(); } response.setError(false); response.setData(root1); } finally { // ?? if (progressMsg.length() > 0) { AbstractActivity.PROGRESS_MESSAGE = AbstractActivity.DEFAULT_PROGRESS_MESSAGE; } // ? ?? ? ?. long end = System.currentTimeMillis(); long processTime = end - start; if (processTime < 200 && processTime > 0) { try { Thread.sleep(200 - processTime); } catch (InterruptedException e) { } } } response.setRequest(request); setResponse(response); return response; }
From source file:com.prey.PreyPhone.java
public String getLine1Number() { TelephonyManager tManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); String line1Number = ""; try {/*from ww w. jav a 2s. c om*/ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ctx.checkSelfPermission( android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { line1Number = tManager.getLine1Number(); } } else { line1Number = tManager.getLine1Number(); } } catch (Exception e) { PreyLogger.e("Error getDataState:" + e.getMessage(), e); } return line1Number; }
From source file:com.moez.QKSMS.mmssms.Transaction.java
private String fetchRnrSe(String authToken, Context context) throws ExecutionException, InterruptedException { JsonObject userInfo = Ion.with(context).load("https://www.google.com/voice/request/user") .setHeader("Authorization", "GoogleLogin auth=" + authToken).asJsonObject().get(); String rnrse = userInfo.get("r").getAsString(); try {// ww w . j a v a 2s . com TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE); String number = tm.getLine1Number(); if (number != null) { JsonObject phones = userInfo.getAsJsonObject("phones"); for (Map.Entry<String, JsonElement> entry : phones.entrySet()) { JsonObject phone = entry.getValue().getAsJsonObject(); if (!PhoneNumberUtils.compare(number, phone.get("phoneNumber").getAsString())) continue; if (!phone.get("smsEnabled").getAsBoolean()) break; Ion.with(context).load("https://www.google.com/voice/settings/editForwardingSms/") .setHeader("Authorization", "GoogleLogin auth=" + authToken) .setBodyParameter("phoneId", entry.getKey()).setBodyParameter("enabled", "0") .setBodyParameter("_rnr_se", rnrse).asJsonObject(); break; } } } catch (Exception e) { } // broadcast so you can save it to your shared prefs or something so that it doesn't need to be retrieved every time Intent intent = new Intent(VOICE_TOKEN); intent.putExtra("_rnr_se", rnrse); context.sendBroadcast(intent); return rnrse; }
From source file:org.cryptsecure.Utility.java
/** * Gets the phone number.//from w w w . j av a 2 s.c om * * @param context * the context * @return the phone number */ public static String getPhoneNumber(Context context) { TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number(); return mPhoneNumber; }
From source file:com.landenlabs.all_devtool.NetFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();// w ww . ja va 2 s .com // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Connection Services ------------- try { ConnectivityManager connMgr = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); if (netInfo != null) { Map<String, String> netListStr = new LinkedHashMap<String, String>(); putIf(netListStr, "Available", "Yes", netInfo.isAvailable()); putIf(netListStr, "Connected", "Yes", netInfo.isConnected()); putIf(netListStr, "Connecting", "Yes", !netInfo.isConnected() && netInfo.isConnectedOrConnecting()); putIf(netListStr, "Roaming", "Yes", netInfo.isRoaming()); putIf(netListStr, "Extra", netInfo.getExtraInfo(), !TextUtils.isEmpty(netInfo.getExtraInfo())); putIf(netListStr, "WhyFailed", netInfo.getReason(), !TextUtils.isEmpty(netInfo.getReason())); if (Build.VERSION.SDK_INT >= 16) { putIf(netListStr, "Metered", "Avoid heavy use", connMgr.isActiveNetworkMetered()); } netListStr.put("NetworkType", netInfo.getTypeName()); if (connMgr.getAllNetworkInfo().length > 1) { netListStr.put("Available Networks:", " "); for (NetworkInfo netI : connMgr.getAllNetworkInfo()) { if (netI.isAvailable()) { netListStr.put(" " + netI.getTypeName(), netI.isAvailable() ? "Yes" : "No"); } } } if (netInfo.isConnected()) { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress.getHostAddress() != null) { String ipType = (inetAddress instanceof Inet4Address) ? "IPv4" : "IPv6"; netListStr.put(intf.getName() + " " + ipType, inetAddress.getHostAddress()); } // if (!TextUtils.isEmpty(inetAddress.getHostName())) // listStr.put( "HostName", inetAddress.getHostName()); } } } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } } addBuild("Network...", netListStr); } } catch (Exception ex) { m_log.e("Network %s", ex.getMessage()); } // --------------- Telephony Services ------------- TelephonyManager telephonyManager = (TelephonyManager) getActivity() .getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { Map<String, String> cellListStr = new LinkedHashMap<String, String>(); try { cellListStr.put("Version", telephonyManager.getDeviceSoftwareVersion()); cellListStr.put("Number", telephonyManager.getLine1Number()); cellListStr.put("Service", telephonyManager.getNetworkOperatorName()); cellListStr.put("Roaming", telephonyManager.isNetworkRoaming() ? "Yes" : "No"); cellListStr.put("Type", getNetworkTypeName(telephonyManager.getNetworkType())); if (Build.VERSION.SDK_INT >= 17) { if (telephonyManager.getAllCellInfo() != null) { for (CellInfo cellInfo : telephonyManager.getAllCellInfo()) { String cellName = cellInfo.getClass().getSimpleName(); int level = 0; if (cellInfo instanceof CellInfoCdma) { level = ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoGsm) { level = ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoLte) { level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel(); } else if (cellInfo instanceof CellInfoWcdma) { if (Build.VERSION.SDK_INT >= 18) { level = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel(); } } cellListStr.put(cellName, "Level% " + String.valueOf(100 * level / 4)); } } } for (NeighboringCellInfo cellInfo : telephonyManager.getNeighboringCellInfo()) { int level = cellInfo.getRssi(); cellListStr.put("Cell level%", String.valueOf(100 * level / 31)); } } catch (Exception ex) { m_log.e("Cell %s", ex.getMessage()); } if (!cellListStr.isEmpty()) { addBuild("Cell...", cellListStr); } } // --------------- Bluetooth Services (API18) ------------- if (Build.VERSION.SDK_INT >= 18) { try { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { Map<String, String> btListStr = new LinkedHashMap<String, String>(); btListStr.put("Enabled", bluetoothAdapter.isEnabled() ? "yes" : "no"); btListStr.put("Name", bluetoothAdapter.getName()); btListStr.put("ScanMode", String.valueOf(bluetoothAdapter.getScanMode())); btListStr.put("State", String.valueOf(bluetoothAdapter.getState())); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView btListStr.put("Paired:" + device.getName(), device.getAddress()); } } BluetoothManager btMgr = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); if (btMgr != null) { // btMgr.getAdapter(). } addBuild("Bluetooth", btListStr); } } catch (Exception ex) { } } // --------------- Wifi Services ------------- final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { if (mSystemBroadcastReceiver == null) { mSystemBroadcastReceiver = new SystemBroadcastReceiver(wifiMgr); getActivity().registerReceiver(mSystemBroadcastReceiver, INTENT_FILTER_SCAN_AVAILABLE); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (wifiMgr.getScanResults() == null || wifiMgr.getScanResults().size() != mLastScanSize) { mLastScanSize = wifiMgr.getScanResults().size(); wifiMgr.startScan(); } } Map<String, String> wifiListStr = new LinkedHashMap<String, String>(); try { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); wifiListStr.put("DNS1", Formatter.formatIpAddress(dhcpInfo.dns1)); wifiListStr.put("DNS2", Formatter.formatIpAddress(dhcpInfo.dns2)); wifiListStr.put("Default Gateway", Formatter.formatIpAddress(dhcpInfo.gateway)); wifiListStr.put("IP Address", Formatter.formatIpAddress(dhcpInfo.ipAddress)); wifiListStr.put("Subnet Mask", Formatter.formatIpAddress(dhcpInfo.netmask)); wifiListStr.put("Server IP", Formatter.formatIpAddress(dhcpInfo.serverAddress)); wifiListStr.put("Lease Time(sec)", String.valueOf(dhcpInfo.leaseDuration)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); if (wifiInfo != null) { wifiListStr.put("LinkSpeed Mbps", String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); wifiListStr.put("Signal%", String.valueOf(100 * level / numberOfLevels)); if (Build.VERSION.SDK_INT >= 23) { wifiListStr.put("MAC", getMacAddr()); } else { wifiListStr.put("MAC", wifiInfo.getMacAddress()); } } } catch (Exception ex) { m_log.e("Wifi %s", ex.getMessage()); } if (!wifiListStr.isEmpty()) { addBuild("WiFi...", wifiListStr); } try { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { List<ScanResult> listWifi = wifiMgr.getScanResults(); if (listWifi != null && !listWifi.isEmpty()) { int idx = 0; for (ScanResult scanResult : listWifi) { Map<String, String> wifiScanListStr = new LinkedHashMap<String, String>(); wifiScanListStr.put("SSID", scanResult.SSID); if (Build.VERSION.SDK_INT >= 23) { wifiScanListStr.put(" Name", scanResult.operatorFriendlyName.toString()); wifiScanListStr.put(" Venue", scanResult.venueName.toString()); } // wifiScanListStr.put(" BSSID ",scanResult.BSSID); wifiScanListStr.put(" Capabilities", scanResult.capabilities); // wifiScanListStr.put(" Center Freq", String.valueOf(scanResult.centerFreq0)); // wifiScanListStr.put(" Freq width", String.valueOf(scanResult.channelWidth)); wifiScanListStr.put(" Level, Freq", String.format("%d, %d", scanResult.level, scanResult.frequency)); if (Build.VERSION.SDK_INT >= 17) { Date wifiTime = new Date(scanResult.timestamp); wifiScanListStr.put(" Time", wifiTime.toLocaleString()); } addBuild(String.format("WiFiScan #%d", ++idx), wifiScanListStr); } } } } catch (Exception ex) { m_log.e("WifiList %s", ex.getMessage()); } try { List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks(); for (WifiConfiguration wifiCfg : listWifiCfg) { Map<String, String> wifiCfgListStr = new LinkedHashMap<String, String>(); if (Build.VERSION.SDK_INT >= 23) { wifiCfgListStr.put("Name", wifiCfg.providerFriendlyName); } wifiCfgListStr.put("SSID", wifiCfg.SSID); String netStatus = ""; switch (wifiCfg.status) { case WifiConfiguration.Status.CURRENT: netStatus = "Connected"; break; case WifiConfiguration.Status.DISABLED: netStatus = "Disabled"; break; case WifiConfiguration.Status.ENABLED: netStatus = "Enabled"; break; } wifiCfgListStr.put(" Status", netStatus); wifiCfgListStr.put(" Priority", String.valueOf(wifiCfg.priority)); if (null != wifiCfg.wepKeys) { // wifiCfgListStr.put(" wepKeys", TextUtils.join(",", wifiCfg.wepKeys)); } String protocols = ""; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) protocols = "RSN "; if (wifiCfg.allowedProtocols.get(WifiConfiguration.Protocol.WPA)) protocols = protocols + "WPA "; wifiCfgListStr.put(" Protocols", protocols); String keyProt = ""; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) keyProt = "none"; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) keyProt = "WPA+EAP "; if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) keyProt = "WPA+PSK "; wifiCfgListStr.put(" Keys", keyProt); if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { // Remove network connections with no Password. // wifiMgr.removeNetwork(wifiCfg.networkId); } addBuild("WiFiCfg #" + wifiCfg.networkId, wifiCfgListStr); } } catch (Exception ex) { m_log.e("Wifi Cfg List %s", ex.getMessage()); } } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
private String getDeviceNumber() { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return tm.getLine1Number(); }