我不是Java开发人员,但我正在尝试为Android的Cordova插件添加更多数据。
我不明白为什么不允许这样做?在这里,我试图用方法设置asu的值。
int asu = getSignalStrength();
The method below:
int signalStrength = 0;
private int getSignalStrength(CellSignalStrength signal) {
signalStrength = signal.getAsuLevel();
return signalStrength;
}
以下错误:
类Sim中的方法getSignalStrength不能应用于给定 类型; int asu = getSignalStrength();
它们不是两种int类型吗?我错了什么
答案 0 :(得分:1)
调用getSignalStrength()时必须添加参数; 如下 -
int asu = getSignalStrength(signal);
答案 1 :(得分:1)
首先创建一个CellSignalStrength的新实例:
final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
CellInfoGsm cellInfoGsm = (CellInfoGsm) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength();
cellSignalStrengthGsm.getDbm();
然后您可以在方法中将其作为参数传递
int asu = getSignalStrength(cellSignalStrengthGsm);
答案 2 :(得分:0)
我只想分享它最终的样子:
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = manager.getAllCellInfo(); //This will give info of all sims present inside your mobile
int asu = 0;
if(cellInfos!=null){
for (int i = 0 ; i<cellInfos.size(); i++){
if (cellInfos.get(i).isRegistered()){
if (cellInfos.get(i) instanceof CellInfoWcdma) {
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) manager.getAllCellInfo().get(0);
CellSignalStrength strength = cellInfoWcdma.getCellSignalStrength();
asu = getSignalStrength(strength);
} else if(cellInfos.get(i) instanceof CellInfoGsm) {
CellInfoGsm cellInfogsm = (CellInfoGsm) manager.getAllCellInfo().get(0);
CellSignalStrength strength = cellInfogsm.getCellSignalStrength();
asu = getSignalStrength(strength);
} else if(cellInfos.get(i) instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) manager.getAllCellInfo().get(0);
CellSignalStrength strength = cellInfoLte.getCellSignalStrength();
asu = getSignalStrength(strength);
}
}
}
}