我尝试在这里使用一些答案来为 Signal Quality 创建一个 Cordova 插件(它可以是 dBm 或 0-4 级别),但没有任何效果。
那些使用 PhoneStateListener 的效果并不好,因为在 Cordova 中你需要创建这种类型的类:
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("signal")){
任何帮助将不胜感激。
提前致谢。
编辑: 我已经阅读了与此相关的 Android 开发者页面:http: //developer.android.com/reference/android/telephony/PhoneStateListener.html http://developer.android.com/reference/android/telephony/SignalStrength .html
但我什么也没想到。我对这个插件感到非常沮丧,因为它是最后一个,一旦完成,项目也完成了。
谢谢, MYS77
编辑 2
我已经使用了这些代码:
1:
CellInfo allCellInfo = (CellInfo) tm.getAllCellInfo().get(0); CellSignalStrength cellSignalStrength = ((CellInfoGsm) allCellInfo).getCellSignalStrength(); level = cellSignalStrength.getLevel();
2:
List<NeighboringCellInfo> neighbors = tm.getNeighboringCellInfo(); for (NeighboringCellInfo n : neighbors) { if (n.getRssi() != NeighboringCellInfo.UNKNOWN_RSSI) { dbm = n.getRssi(); }
3:
TelephonyManager tm = (TelephonyManager)cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); MyPhoneStateListener MyListener; @Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { boolean result = false; String level = ""; if (action.equals("signal")){ try{ tm.listen(MyListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); callbackContext.success("Hey!"); level = MyListener.getStrength(); } catch (Exception ex) { callbackContext.error("ERROR"); } finally{ if (level != "") { callbackContext.success("Signal Strength = "+level); } else{ callbackContext.success("Could not retrieve signal quality."); } } } return result; } } class MyPhoneStateListener extends PhoneStateListener{ String gsmStrength = ""; @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { super.onSignalStrengthsChanged(signalStrength); gsmStrength = String.valueOf(signalStrength.getGsmSignalStrength()* 2 - 113); } public String getStrength() { return gsmStrength; }
它们不会产生任何错误,但是当我在 Xperia M2 Aqua 上进行测试时,它会不断发送“无效操作”作为响应。