opt traffic light panel

This commit is contained in:
tongchenfei
2020-12-17 20:04:00 +08:00
parent 886ba900cc
commit 7848be8ea6
7 changed files with 170 additions and 3 deletions

View File

@@ -3,6 +3,10 @@ package com.mogo.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import androidx.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -107,4 +111,17 @@ public class NetworkUtils {
return matcher.matches();
}
public static int netStrengthLevel = 0;
public static void listenNetStrength(Context context) {
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
manager.listen(new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
netStrengthLevel = signalStrength.getLevel();
}
}, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
}