Reputation: 11
I have an app which shows the current signal strength, in many phones it is working, but when I test it on a Huawei phone, it is always 0, at the same time the signal bars are full in that huawei phone. what is the problem? is it related to android version? is it related to permissions? i have this:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Upvotes: 1
Views: 809
Reputation: 3183
It's not always zero. The way you are getting the signal strength is wrong. In some of the phones, it could be zero may be the removal of api.
Just try this code if it works for you.
String gsmSignalStrength=null;
String ssignal = asu.toString();
String[] parts = ssignal.split(" ");
int currentStrength = asu.getGsmSignalStrength();
if (currentStrength <= 0) {
gsmSignalStrength= String
.valueOf(Integer.parseInt(parts[3]));
} else {
gsmSignalStrength= String.valueOf(-113 + 2 * asu.getGsmSignalStrength());
}
Log.d(TAG,"Signal Strength : "+gsmSignalStrength);
This will works only for GSM ;
The parts array elements are described as
parts[1] = GsmSignalStrength
parts[3] = CDMADBM
parts[8] = LteSignalStrength
parts[9] = LteRsrp
parts[10] = LteRsrq
parts[13] = gsm|lte
So you can put some condition to extract value from this array.
Upvotes: 1