No virtual method getCellSignalStrength()

467 Views Asked by At

I need the GSM signal strength described in the following paper on android:

enter image description here

Source: https://www.researchgate.net/publication/308578251_Indoor-Outdoor_Detection_Using_a_Smart_Phone_Sensor

When i run the following code:

TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO
        return;
    }
    List<CellInfo> cellInfoList = manager.getAllCellInfo();
    System.out.println(cellInfoList.get(0).getCellSignalStrength());
}

I get the following error:

W/r_detection_ap( 5718): Accessing hidden method Landroid/telephony/CellInfo;->getCellSignalStrength()Landroid/telephony/CellSignalStrength; (blacklist, linking, denied)
E/AndroidRuntime( 5718): FATAL EXCEPTION: main
E/AndroidRuntime( 5718): Process: de.felithium.indoor_outdoor_detection_app, PID: 5718
E/AndroidRuntime( 5718): java.lang.NoSuchMethodError: No virtual method getCellSignalStrength()Landroid/telephony/CellSignalStrength; in class Landroid/telephony/CellInfo; or its super classes (declaration of 'android.telephony.CellInfo' appears in /system/framework/framework.jar!classes2.dex)
E/AndroidRuntime( 5718):    at de.felithium.indoor_outdoor_detection_app.MainActivity.lambda$configureFlutterEngine$0$MainActivity(MainActivity.java:43)
E/AndroidRuntime( 5718):    at de.felithium.indoor_outdoor_detection_app.-$$Lambda$MainActivity$gCCACi3_KGae1eavG8OYIDKJz3Y.onMethodCall(Unknown Source:2)
E/AndroidRuntime( 5718):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime( 5718):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AndroidRuntime( 5718):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/AndroidRuntime( 5718):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime( 5718):    at android.os.MessageQueue.next(MessageQueue.java:336)
E/AndroidRuntime( 5718):    at android.os.Looper.loop(Looper.java:174)
E/AndroidRuntime( 5718):    at android.app.ActivityThread.main(ActivityThread.java:7710)
E/AndroidRuntime( 5718):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5718):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
E/AndroidRuntime( 5718):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
I/Process ( 5718): Sending signal. PID: 5718 SIG: 9
Lost connection to device.

I get the error only on my smartphone (One Plus 7 Pro), while it works on the Emulator. According to the Docs getCellSignalStrength was implemented in SDK Version 17 but both my smartphone and the emulator have SDK Version 29. Any ideas why I get this error or if there is another way to get the desired values consistently?

0

There are 0 best solutions below