Au niveau de l'API 17 seulement, voici un code qui peut être utilisé dans un Activity
(ou toute autre classe Context
enfant):
import android.telephony.CellInfo;
import android.telephony.CellInfoCdma;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellSignalStrengthCdma;
import android.telephony.CellSignalStrengthGsm;
import android.telephony.CellSignalStrengthLte;
import android.telephony.TelephonyManager;
try {
final TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
for (final CellInfo info : tm.getAllCellInfo()) {
if (info instanceof CellInfoGsm) {
final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
// do what you need
} else if (info instanceof CellInfoCdma) {
final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
// do what you need
} else if (info instanceof CellInfoLte) {
final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
// do what you need
} else {
throw new Exception("Unknown type of cell signal!");
}
}
} catch (Exception e) {
Log.e(TAG, "Unable to obtain cell signal information", e);
}
versions précédentes d'Android nécessitent d'appeler l'auditeur, il n'est pas une autre alternative (voir this link).
Assurez-vous également que votre application contient les autorisations appropriées.
Je reçois seulement 99 pour la force du signal et -1 pour le taux d'erreur binaire. Cela ne semble pas me donner la vraie valeur. savez-vous ce qui pourrait être faux? – user2031865
Selon la puissance du signal GSM, les valeurs valides sont (0-31, 99) comme défini dans TS 27.007 8.5 '0 -113 dBm ou moins 1 -111 dBm 2 ... 30 -109 ... -53 dBm 31 -51 dBm ou plus 99 non connu ou non détectable' voir plus de [3GPP TS 27.007] (http://m10.home.xs4all.nl/mac/downloads/3GPP-27007-630.pdf) –