Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
- if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
- ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- // TODO: Consider calling
- // ActivityCompat#requestPermissions
- // here to request the missing permissions, and then overriding
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
- // int[] grantResults)
- // to handle the case where the user grants the permission. See the documentation
- // for ActivityCompat#requestPermissions for more details.
- }
- GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
- String networkOperator = telephonyManager.getNetworkOperator();
- String networOperatorName = telephonyManager.getNetworkOperatorName();
- String networkTyInfo = String.valueOf(telephonyManager.getNetworkType());
- int mnc = 0, mcc = 0;
- if (!TextUtils.isEmpty(networkOperator)) {
- mcc = Integer.parseInt(networkOperator.substring(0, 3));
- mnc = Integer.parseInt(networkOperator.substring(3));
- }
- int cid =0;
- int lac = 0;
- if (cellLocation != null) {
- cid = cellLocation.getCid();
- lac = cellLocation.getLac();
- }
- GSMValues gsmValues =
- new GSMValues(
- String.valueOf(lac),
- String.valueOf(mcc),
- String.valueOf(mnc),
- String.valueOf(cid),
- String.valueOf(0),
- networkTyInfo,
- signalStrength,
- networOperatorName
- );
- // db = new DatabaseHelper(getApplicationContext());
- // db.StoreLocations(gsmValues);
- TelephonyManager TM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
- List<NeighboringCellInfo> neighboringCellInfoList = TM.getNeighboringCellInfo();
- if(neighboringCellInfoList != null){
- // iterate the list
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement