48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
package com.qp51.dev;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.net.wifi.WifiInfo;
|
|
import android.net.wifi.WifiManager;
|
|
import android.telephony.PhoneStateListener;
|
|
import android.telephony.SignalStrength;
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import com.unity3d.player.UnityPlayer;
|
|
|
|
public class GetWIFIRssi {
|
|
public static int GetWIFISignalStrength() {
|
|
final Activity activity = UnityPlayer.currentActivity;
|
|
final Context context = activity.getApplicationContext();
|
|
|
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
int numberOfLevels = 5;
|
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
|
|
// Log.i("Unity", "wifi level:"+level);
|
|
return level;
|
|
}
|
|
|
|
private static final class MyPhoneStateListener extends PhoneStateListener {
|
|
@Override
|
|
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
|
super.onSignalStrengthsChanged(signalStrength);
|
|
teleLevel = signalStrength.getLevel();
|
|
}
|
|
}
|
|
|
|
static void TelephonyManagerListen() {
|
|
final Activity activity = UnityPlayer.currentActivity;
|
|
final Context context = activity.getApplicationContext();
|
|
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
tm.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
|
}
|
|
|
|
private static int teleLevel = 0;
|
|
|
|
public static int GetTeleSignalStrength() {
|
|
// Log.i("Unity", "xh level:"+teleLevel);
|
|
return teleLevel;
|
|
}
|
|
}
|