ここでいくつかの回答を使用して、信号品質用の Cordova プラグインを作成しようとしましたが (dBm または 0-4 レベルにすることができます)、何も機能しませんでした。
Cordova では、このタイプのクラスを作成する必要があるため、PhoneStateListener を持つものも同様に機能しませんでした。
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 でテストすると、応答として「無効なアクション」が送信され続けます。