0

CellSignalStrength is the closest to what i need, but the problem i'm facing is that there is no constructor to use the class, and I tried to make a new class and extend it, it didn't work, the android documentation is good, without offering one small piece of code to follow, I don't know what to do.

i'm using API 8, which doesn't support that class, what should I do ?

Omar Awamry
  • 1,462
  • 3
  • 15
  • 29

1 Answers1

0
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> all = telephonyManager.getAllCellInfo();
CellInfoGsm cellinfogsm = (CellInfoGsm) all.get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
int strengthDbm = cellSignalStrengthGsm.getDbm();

should work fine for API 17+. I am not aware of any API to help <17, though.

Eric Cochran
  • 8,414
  • 5
  • 50
  • 91
  • i've made a new project with the API 17 to test this. it gives error message "can not resolve symbol context" , the one in the first line. – Omar Awamry Jan 19 '16 at 02:20
  • The `context` reference there could be your `Activity`, most likely. (https://developer.android.com/reference/android/content/Context.html) – Eric Cochran Jan 19 '16 at 02:23
  • I tried this but didn't work : TelephonyManager telephonyManager = (TelephonyManager) activity_main.getSystemService(Context.TELEPHONY_SERVICE); – Omar Awamry Jan 19 '16 at 02:29
  • if you are using `Activity` try `getApplicationContext().getSystemService..` – Dhinakaran Thennarasu Jan 19 '16 at 03:26
  • The "List" list always returns empty, i read here that it's not implemented on all devices : http://stackoverflow.com/questions/16541172/getallcellinfo-returns-null-in-android-4-2-1/18688268#18688268 – Omar Awamry Jan 19 '16 at 08:37
  • my phone has android 4.4.4 – Omar Awamry Jan 19 '16 at 08:38
  • java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference 03-28 14:35:42.117 16909-16909/com.example.tene11.lockappnew W/System.err: at com.example.tene11.lockappnew.Data.SimInfo.getSimInfo(SimInfo.java:29) 03-28 14:35:42.117 16909-16909/com.example.tene11.lockappnew W/System.err: at com.example.tene11.lockappnew.services.DeviceStatus.onReceive(DeviceStatus.java:98) 03-28 14:35:42.117 16909-16909/com.example.tene11.lockappnew – Karthik Mar 28 '17 at 09:14