本文整理匯總了Java中android.telephony.SignalStrength類的典型用法代碼示例。如果您正苦於以下問題:Java SignalStrength類的具體用法?Java SignalStrength怎麽用?Java SignalStrength使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SignalStrength類屬於android.telephony包,在下文中一共展示了SignalStrength類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupSignalStrength
import android.telephony.SignalStrength; //導入依賴的package包/類
private void setupSignalStrength() {
final TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final ImageView signalIcon = ((ImageView) statusBar.findViewById(R.id.signal_icon));
phoneListener = new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
if (manager.getNetworkOperator().equals("")) {
signalIcon.setVisibility(View.GONE);
} else {
signalIcon.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// See https://github.com/AlstonLin/TheLearningLock/issues/54
Integer imageRes = signalStrengthToIcon.get(signalStrength.getLevel());
if (imageRes != null) signalIcon.setImageResource(imageRes);
else signalIcon.setImageResource(signalStrengthToIcon.get(4));
} else {
// Just show the full icon
signalIcon.setImageResource(signalStrengthToIcon.get(4));
}
}
}
};
manager.listen(phoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
示例2: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
/**
* Description: TODO: add more info
*
* Issues:
*
* [ ] Getting and comparing signal strengths between different RATs can be very
* tricky, since they all return different ranges of values. AOS doesn't
* specify very clearly what exactly is returned, even though people have
* a good idea, by trial and error.
*
* See note in : SignalStrengthTracker.java
*
* Notes:
*
*
*
*/
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
// Update Signal Strength
if (signalStrength.isGsm()) {
int dbm;
if (signalStrength.getGsmSignalStrength() <= 2 ||
signalStrength.getGsmSignalStrength() == NeighboringCellInfo.UNKNOWN_RSSI) {
// Unknown signal strength, get it another way
String[] bits = signalStrength.toString().split(" ");
dbm = Integer.parseInt(bits[9]);
} else {
dbm = signalStrength.getGsmSignalStrength();
}
mDevice.setSignalDbm(dbm);
} else {
int evdoDbm = signalStrength.getEvdoDbm();
int cdmaDbm = signalStrength.getCdmaDbm();
// Use lowest signal to be conservative
mDevice.setSignalDbm((cdmaDbm < evdoDbm) ? cdmaDbm : evdoDbm);
}
// Send it to signal tracker
signalStrengthTracker.registerSignalStrength(mDevice.mCell.getCID(), mDevice.getSignalDBm());
//signalStrengthTracker.isMysterious(mDevice.mCell.getCID(), mDevice.getSignalDBm());
}
示例3: phoneSignalStrengthsUpdated
import android.telephony.SignalStrength; //導入依賴的package包/類
@Override
public void phoneSignalStrengthsUpdated(SignalStrength signalStrength) {
WritableMap map = Arguments.createMap();
map.putInt("cdmaDbm", signalStrength.getCdmaDbm());
map.putInt("cdmaEcio()", signalStrength.getCdmaEcio());
map.putInt("evdoDbm", signalStrength.getEvdoDbm());
map.putInt("evdoEcio", signalStrength.getEvdoEcio());
map.putInt("evdoSnr", signalStrength.getEvdoSnr());
map.putInt("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
map.putInt("gsmSignalStrength", signalStrength.getGsmSignalStrength());
map.putBoolean("gsm", signalStrength.isGsm());
WritableMap result = Arguments.createMap();
result.putString("type", "LISTEN_SIGNAL_STRENGTHS");
result.putMap("data", map);
sendEvent(PHONE_STATE_LISTENER, result);
}
示例4: updateSignalStrength
import android.telephony.SignalStrength; //導入依賴的package包/類
private void updateSignalStrength(SignalStrength signalStrength) {
final int level;
Log.i(TAG, "updateSignalStrength: ");
if(!isCdma(signalStrength)) {
int asu = signalStrength.getGsmSignalStrength();
// ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
// asu = 0 (-113dB or less) is very weak
// signal, its better to show 0 bars to the user in such cases.
// asu = 99 is a special case, where the signal strength is unknown.
if(asu <= 2 || asu == 99) level = EventSubCodes.SAMSUNG_SIGNAL_STRENGTH_EVT_NO_BAR;
else if(asu >= 12) level = EventSubCodes.SAMSUNG_SIGNAL_STRENGTH_EVT_FOUR_BAR;
else if(asu >= 8) level = EventSubCodes.SAMSUNG_SIGNAL_STRENGTH_EVT_THREE_BAR;
else if(asu >= 5) level = EventSubCodes.SAMSUNG_SIGNAL_STRENGTH_EVT_TWO_BAR;
else level = EventSubCodes.SAMSUNG_SIGNAL_STRENGTH_EVT_ONE_BAR;
} else {
level = getCdmaLevel(signalStrength);
}
if(level != sCurrentSignalStrength) {
sCurrentSignalStrength = level;
MBApp application = MBApp.getApp();
Intent intent = new Intent(application, IPCService.class);
intent.putExtra(IPCConstants.INTENT_TYPE, EventCategories.IPC_BLE_NOTIFICATION_CHARACTERISTIC_CHANGED);
intent.putExtra(IPCConstants.INTENT_CHARACTERISTIC_MESSAGE, Utils.makeMicroBitValue
(EventCategories.SAMSUNG_SIGNAL_STRENGTH_ID, level));
application.startService(intent);
}
}
示例5: getCdmaLevel
import android.telephony.SignalStrength; //導入依賴的package包/類
private int getCdmaLevel(SignalStrength signalStrength) {
final int cdmaDbm = signalStrength.getCdmaDbm();
final int cdmaEcio = signalStrength.getCdmaEcio();
final int levelDbm;
if(cdmaDbm >= -75) levelDbm = 4;
else if(cdmaDbm >= -85) levelDbm = 3;
else if(cdmaDbm >= -95) levelDbm = 2;
else if(cdmaDbm >= -100) levelDbm = 1;
else levelDbm = 0;
final int levelEcio;
// Ec/Io are in dB*10
if(cdmaEcio >= -90) levelEcio = 4;
else if(cdmaEcio >= -110) levelEcio = 3;
else if(cdmaEcio >= -130) levelEcio = 2;
else if(cdmaEcio >= -150) levelEcio = 1;
else levelEcio = 0;
return (levelDbm < levelEcio) ? levelDbm : levelEcio;
}
示例6: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
/**
* Description: TODO: add more info
*
* Issues:
*
* [ ] Getting and comparing signal strengths between different RATs can be very
* tricky, since they all return different ranges of values. AOS doesn't
* specify very clearly what exactly is returned, even though people have
* a good idea, by trial and error.
*
* See note in : SignalStrengthTracker.java
*/
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
// Update Signal Strength
if (signalStrength.isGsm()) {
int dbm;
if (signalStrength.getGsmSignalStrength() <= 2 ||
signalStrength.getGsmSignalStrength() == NeighboringCellInfo.UNKNOWN_RSSI) {
// Unknown signal strength, get it another way
String[] bits = signalStrength.toString().split(" ");
dbm = Integer.parseInt(bits[9]);
} else {
dbm = signalStrength.getGsmSignalStrength();
}
device.setSignalDbm(dbm);
} else {
int evdoDbm = signalStrength.getEvdoDbm();
int cdmaDbm = signalStrength.getCdmaDbm();
// Use lowest signal to be conservative
device.setSignalDbm((cdmaDbm < evdoDbm) ? cdmaDbm : evdoDbm);
}
// Send it to signal tracker
signalStrengthTracker.registerSignalStrength(device.cell.getCellId(), device.getSignalDBm());
//signalStrengthTracker.isMysterious(device.cell.getCid(), device.getSignalDBm());
}
示例7: getFirstValid
import android.telephony.SignalStrength; //導入依賴的package包/類
public static double getFirstValid(SignalStrength signalStrength) {
for (SignalMethod method : methods) {
if (method.isExcluded()) continue;
double level;
try {
level = method.getLevel(signalStrength);
} catch (Exception e) {
continue;
}
if (SignalUtils.isValidLevel(level) && level > 0)
return level;
}
return 0;
}
示例8: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
/**
* signalStrength.isGsm() 是否GSM信號 2G or 3G
* signalStrength.getCdmaDbm(); 聯通3G 信號強度
* signalStrength.getCdmaEcio(); 聯通3G 載幹比
* signalStrength.getEvdoDbm(); 電信3G 信號強度
* signalStrength.getEvdoEcio(); 電信3G 載幹比
* signalStrength.getEvdoSnr(); 電信3G 信噪比
* signalStrength.getGsmSignalStrength(); 2G 信號強度
* signalStrength.getGsmBitErrorRate(); 2G 誤碼率
* 載幹比 ,它是指空中模擬電波中的信號與噪聲的比值
*/
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
Log.d(TAG, "onSignalStrengthsChanged() called with " + "signalStrength :"+signalStrength+";\n gsmSignalStrength = [" + signalStrength.getGsmSignalStrength() + "]");
// if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
// mTvSignalInfo.setText("GSM Strength" + signalStrength.getGsmSignalStrength());
// } else if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
// mTvSignalInfo.setText("CDMA Strength" + signalStrength.getCdmaDbm() + " dBm");
// } else {
// mTvSignalInfo.setText("Unknown PhoneType: " + mTelephonyManager.getPhoneType());
// }
mTvSignalInfo.setText("IsGsm : " + signalStrength.isGsm() +
"\nCDMA Dbm : " + signalStrength.getCdmaDbm() + " Dbm" +
"\nCDMA Ecio : " + signalStrength.getCdmaEcio() + " dB*10" +
"\nEvdo Dbm : " + signalStrength.getEvdoDbm() + " Dbm" +
"\nEvdo Ecio : " + signalStrength.getEvdoEcio() + " dB*10" +
"\nGsm SignalStrength : " + signalStrength.getGsmSignalStrength() +
"\nGsm BitErrorRate : " + signalStrength.getGsmBitErrorRate());
}
示例9: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
long now = System.currentTimeMillis();
if (signalStrength.isGsm()) {
Log.d(TAG,
"GSM Signal Strength: "
+ signalStrength.getGsmSignalStrength() + ", "
+ signalStrength.getGsmBitErrorRate());
} else {
Log.d(TAG,
"CDMA Signal Strength: " + signalStrength.getCdmaDbm()
+ ", " + signalStrength.getCdmaEcio());
}
putValueTrimSize(IS_GSM_FIELD, null, now, signalStrength.isGsm());
putValueTrimSize(GSM_SIGNAL_STRENGTH_FIELD, null, now, signalStrength.getGsmSignalStrength());
putValueTrimSize(GSM_BIT_ERROR_RATE_FIELD, null, now, signalStrength.getGsmBitErrorRate());
putValueTrimSize(CDMA_DBM_FIELD, null, now, signalStrength.getCdmaDbm());
putValueTrimSize(CDMA_ECIO_FIELD, null, now, signalStrength.getCdmaEcio());
putValueTrimSize(EVDO_DBM_FIELD, null, now, signalStrength.getEvdoDbm());
putValueTrimSize(EVDO_ECIO_FIELD, null, now, signalStrength.getEvdoEcio());
putValueTrimSize(EVDO_SNR_FIELD, null, now, signalStrength.getEvdoSnr());
}
示例10: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
long now = System.currentTimeMillis();
if (signalStrength.isGsm()) {
Log.d(TAG,
"GSM Signal Strength: "
+ signalStrength.getGsmSignalStrength() + ", "
+ signalStrength.getGsmBitErrorRate());
} else {
Log.d(TAG,
"CDMA Signal Strength: " + signalStrength.getCdmaDbm()
+ ", " + signalStrength.getCdmaEcio());
}
putValueTrimSize(IS_GSM_FIELD, null, now, signalStrength.isGsm());
putValueTrimSize(GSM_SIGNAL_STRENGTH_FIELD, null, now, signalStrength.getGsmSignalStrength());
putValueTrimSize(GSM_BIT_ERROR_RATE_FIELD, null, now, signalStrength.getGsmBitErrorRate());
putValueTrimSize(CDMA_DBM_FIELD, null, now, signalStrength.getCdmaDbm());
putValueTrimSize(CDMA_ECIO_FIELD, null, now, signalStrength.getCdmaEcio());
putValueTrimSize(EVDO_DBM_FIELD, null, now, signalStrength.getEvdoDbm());
putValueTrimSize(EVDO_ECIO_FIELD, null, now, signalStrength.getEvdoEcio());
putValueTrimSize(EVDO_SNR_FIELD, null, now, signalStrength.getEvdoSnr());
}
示例11: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
Log.i(TAG, "onSignalStrengthsChanged" + signalStrength);
// if(Build.VERSION.SDK_INT>=18){
// if(signalStrength instanceof SignalStrength){
// Log.i("LOG_TAG", "onSignalStrengthsChanged: getcdaRscp" + signalStrength.getDbm());
// int ttt = signalStrength.getDbm();
// text1.setText(String.valueOf(ttt));
// }
// else{
Log.i(TAG, "onSignalStrengthsChanged: getcda dbm: " + signalStrength.getCdmaDbm());
int ttt = signalStrength.getCdmaDbm();
text1.setText(String.valueOf(ttt));
// }
// }
}
示例12: onSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
String sim = UEDevice.getSimType(activity);
mNavigationView.setSingalText(sim);
if (sim.equals("無服務")) {
mNavigationView.setSingalStatus(UISingalView.STATUS_NONE);
return;
}
mNavigationView.setSingalStatus(UISingalView.STATUS_NORMAL);
int level = 0;
if (signalStrength.isGsm()) {
level = signalStrength.getGsmSignalStrength();
}else {
if (sim.equals("中國電信")) {
level = signalStrength.getCdmaDbm();
}else {
level = signalStrength.getEvdoDbm();
}
}
if (level == 0) {
mNavigationView.setSignal(5);
return;
}
if (level < -112) {
mNavigationView.setSignal(0);
}else if (level >= -111 && level < -104) {
mNavigationView.setSignal(1);
}else if (level >= -104 && level < -97) {
mNavigationView.setSignal(2);
}else if (level >= -97 && level < -90) {
mNavigationView.setSignal(3);
}else if (level >= -90 && level < -83) {
mNavigationView.setSignal(4);
}else {
mNavigationView.setSignal(5);
}
}
示例13: sOnSignalStrengthsChanged
import android.telephony.SignalStrength; //導入依賴的package包/類
synchronized static void sOnSignalStrengthsChanged(SignalStrength signalStrength) {
mData.setTime(System.currentTimeMillis());
mData.setSignal(signalStrength);
if (OtherUtils.isThisDeviceAnEmulator() == true) {
// The signal will usuaully be null on the Emulator...
} else {
// On a real device... there should generally be a signal...
SKPorting.sAssert(CellTowersDataCollector.class, mData.getSignal() != null);
}
try {
mData.setCellLocation(mTelManager.getCellLocation());
} catch (SecurityException e) {
// Seen - rarely - on some Android devices.
// Neither user 99999 nor current process has android.permission.ACCESS_COARSE_LOCATION.
SKPorting.sAssert(CellTowersDataCollector.class, false);
}
}
示例14: signalStrengthJSON
import android.telephony.SignalStrength; //導入依賴的package包/類
/**
* Originates from a change in signal strength
* @param signalStrength SignalStrength
* @return JSON
*/
public static String signalStrengthJSON(SignalStrength signalStrength){
final Calendar calendar = Calendar.getInstance();
final JSONObject json = new JSONObject();
try {
json.put("provider", SIGNAL_STRENGTH); // Yep provider and type are same values
json.put("type", SIGNAL_STRENGTH);
json.put("timestamp", calendar.getTimeInMillis());
json.put("cdmaDbm", signalStrength.getCdmaDbm());
json.put("cdmaEcio", signalStrength.getCdmaEcio());
json.put("evdoDbm", signalStrength.getEvdoDbm());
json.put("evdoEcio", signalStrength.getEvdoEcio());
json.put("evdoSnr", signalStrength.getEvdoSnr());
json.put("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
json.put("gsmSignalStrength", signalStrength.getGsmSignalStrength());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
json.put("level", signalStrength.getLevel());
}
json.put("isGSM", signalStrength.isGsm());
}
catch(JSONException exc) {
logJSONException(exc);
}
return json.toString();
}
示例15: isCdma
import android.telephony.SignalStrength; //導入依賴的package包/類
private boolean isCdma(SignalStrength signalStrength) {
return (signalStrength != null) && !signalStrength.isGsm();
}