当前位置: 首页>>代码示例>>Java>>正文


Java BatteryManager.BATTERY_STATUS_UNKNOWN属性代码示例

本文整理汇总了Java中android.os.BatteryManager.BATTERY_STATUS_UNKNOWN属性的典型用法代码示例。如果您正苦于以下问题:Java BatteryManager.BATTERY_STATUS_UNKNOWN属性的具体用法?Java BatteryManager.BATTERY_STATUS_UNKNOWN怎么用?Java BatteryManager.BATTERY_STATUS_UNKNOWN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.os.BatteryManager的用法示例。


在下文中一共展示了BatteryManager.BATTERY_STATUS_UNKNOWN属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setStatus

private void setStatus(int statusValue) {
    String status;

    switch (statusValue) {
        case BatteryManager.BATTERY_STATUS_CHARGING:
            status = getString(R.string.battery_status_charging);
            break;
        case BatteryManager.BATTERY_STATUS_DISCHARGING:
            status = getString(R.string.battery_status_discharging);
            break;
        case BatteryManager.BATTERY_STATUS_FULL:
            status = getString(R.string.battery_status_full);
            break;
        case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
            status = getString(R.string.battery_status_not_charging);
            break;
        case BatteryManager.BATTERY_STATUS_UNKNOWN:
        default:
            status = getString(R.string.battery_status_unknown);
    }

    mViewStatus.setValue(status);
    mBatteryInfo.setStatus(status);
}
 
开发者ID:Smart-Studio,项目名称:device-info,代码行数:24,代码来源:BatteryViewImpl.java

示例2: isCharging

/**
 * Method to check if the device is charging.
 *
 * @return Returns true if device is either charging or full, false otherwise
 */
private boolean isCharging() {
    try {
        Intent batteryIntent = mContext.getApplicationContext().registerReceiver(null,
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        if (batteryIntent != null) {
            int batteryPowerStatus = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);

            switch (batteryPowerStatus) {
                case BatteryManager.BATTERY_STATUS_CHARGING:
                case BatteryManager.BATTERY_STATUS_FULL:
                    return true;

                case BatteryManager.BATTERY_STATUS_UNKNOWN:
                case BatteryManager.BATTERY_STATUS_DISCHARGING:
                case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
                default:
                    return false;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception occurred while isCharging: " + e);
    }

    return false;
}
 
开发者ID:hypertrack,项目名称:smart-scheduler-android,代码行数:30,代码来源:SmartScheduler.java

示例3: translateBatteryStatus

public static String translateBatteryStatus(int batteryStatus) {
    switch (batteryStatus) {
        case BatteryManager.BATTERY_STATUS_CHARGING:
            return "CHARGING";
        case BatteryManager.BATTERY_STATUS_DISCHARGING:
            return "DISCHARGING";
        case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
            return "NOT CHARGING";
        case BatteryManager.BATTERY_STATUS_FULL:
            return "FULL";
        case BatteryManager.BATTERY_STATUS_UNKNOWN:
            return "STATUS UNKNOWN";
        default:
            return "UNKNOWN (" + batteryStatus + ")";
    }
}
 
开发者ID:patrickfav,项目名称:under-the-hood,代码行数:16,代码来源:TypeTranslators.java

示例4: getBatteryStatusText

/** Get readable battery status */
private String getBatteryStatusText(int status) {
    String statusString = getString(R.string.unknown);
    switch (status) {
        case BatteryManager.BATTERY_STATUS_UNKNOWN:
            statusString = getString(R.string.unknown);
            break;
        case BatteryManager.BATTERY_STATUS_CHARGING:
            statusString = getString(R.string.charging);
            break;
        case BatteryManager.BATTERY_STATUS_DISCHARGING:
            statusString = getString(R.string.discharging);
            break;
        case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
            statusString = getString(R.string.not_charging);
            break;
        case BatteryManager.BATTERY_STATUS_FULL:
            statusString = getString(R.string.full);
            break;
    }

    return statusString;
}
 
开发者ID:MotorolaMobilityLLC,项目名称:mdkbattery,代码行数:23,代码来源:MainActivity.java

示例5: getBatteryState

/**
 * https://developer.android.com/training/monitoring-device-state/battery-monitoring.html
 */
public static int getBatteryState(Context context) {
  IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  Intent batteryStatus = context.registerReceiver(null, ifilter);
  if (batteryStatus == null) {
    return BatteryManager.BATTERY_STATUS_UNKNOWN;
  }
  return batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
}
 
开发者ID:airbnb,项目名称:native-navigation,代码行数:11,代码来源:ViewUtils.java

示例6: reset

/** Reset when mod battery is not valid */
private void reset() {
    modBattery = null;
    modEfficiency = ModBattery.BATTERY_USAGE_TYPE_UNKNOWN;
    modUsageType = ModBattery.BATTERY_USAGE_TYPE_UNKNOWN;
    mod.status = BatteryManager.BATTERY_STATUS_UNKNOWN;
}
 
开发者ID:MotorolaMobilityLLC,项目名称:mdkbattery,代码行数:7,代码来源:BatteryPersonality.java

示例7: getBatteryInfo

private void getBatteryInfo() {

        if (fabBatteryCharging != null) {
            if (deviceStatus == BatteryManager.BATTERY_STATUS_CHARGING) {
                fabBatteryCharging.setVisibility(View.VISIBLE);
                fabBatteryCharging.setImageResource(R.drawable.ic_battery);
            }

            if (deviceStatus == BatteryManager.BATTERY_STATUS_DISCHARGING) {
                fabBatteryCharging.setVisibility(View.GONE);
            }

            if (deviceStatus == BatteryManager.BATTERY_STATUS_FULL) {
                fabBatteryCharging.setVisibility(View.GONE);
            }

            if (deviceStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
                fabBatteryCharging.setVisibility(View.GONE);
            }

            if (deviceStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
                fabBatteryCharging.setVisibility(View.GONE);
            }
        }

        final Handler handler = new Handler();
        final Runnable runnable = new Runnable() {
            int counter = 0;
            @Override
            public void run() {
                try {
                    if (counter <= level) {
                        progressBar.setProgress(counter);
                        progressBar.postDelayed(this, 10000);
                        counter++;
                        handler.postDelayed(this, 20);
                    } else {
                        handler.removeCallbacks(this);
                    }
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
            }
        };
        handler.postDelayed(runnable, 20);
        tvBatteryTemperature.setText("".concat(String.valueOf(temperature)));

        if (Validation.isRequiredField(technology)) {
            tvBatteryType.setText("".concat(technology));
        }

        tvBatteryVoltage.setText("".concat(String.valueOf(voltage)));
        tvBatteryScale.setText("".concat(String.valueOf(scale)));
        tvBatteryLevel.setText("".concat(String.valueOf(level)).concat("%"));

        if (health == 1) {
            tvBatteryHealth.setText(mResources.getString(R.string.unknown));
        } else if (health == 2) {
            tvBatteryHealth.setText(mResources.getString(R.string.good));
        } else if (health == 3) {
            tvBatteryHealth.setText(mResources.getString(R.string.over_heated));
        } else if (health == 4) {
            tvBatteryHealth.setText(mResources.getString(R.string.dead));
        } else if (health == 5) {
            tvBatteryHealth.setText(mResources.getString(R.string.over_voltage));
        } else if (health == 6) {
            tvBatteryHealth.setText(mResources.getString(R.string.failed));
        } else {
            tvBatteryHealth.setText(mResources.getString(R.string.cold));
        }

        if (plugged == 1) {
            tvPowerSource.setText(mResources.getString(R.string.ac_power));
        } else {
            tvPowerSource.setText(mResources.getString(R.string.battery));
        }
    }
 
开发者ID:QuixomTech,项目名称:DeviceInfo,代码行数:77,代码来源:BatteryFragment.java

示例8: getStatus

/**
 * Method to resolve the battery status
 */
private void getStatus() {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "getStatus");
    }

    if (batteryIntent != null) {

        final SaiyResources sr = new SaiyResources(mContext, sl);

        final int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS,
                BatteryManager.BATTERY_STATUS_UNKNOWN);

        switch (status) {

            case BatteryManager.BATTERY_STATUS_CHARGING:

                int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED,
                        BatteryManager.BATTERY_STATUS_UNKNOWN);

                switch (plugged) {
                    case BatteryManager.BATTERY_PLUGGED_AC:
                        setStatusResponse(sr.getString(ai.saiy.android.R.string.ac_charging));
                        break;
                    case BatteryManager.BATTERY_PLUGGED_USB:
                        setStatusResponse(sr.getString(ai.saiy.android.R.string.usb_charging));
                        break;
                    default:
                        setStatusResponse(sr.getString(ai.saiy.android.R.string.charging));
                        break;
                }
                break;

            case BatteryManager.BATTERY_STATUS_DISCHARGING:
                setStatusResponse(sr.getString(ai.saiy.android.R.string.discharging));
                break;
            case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
                setStatusResponse(sr.getString(ai.saiy.android.R.string.discharging));
                break;
            case BatteryManager.BATTERY_STATUS_FULL:
                setStatusResponse(sr.getString(ai.saiy.android.R.string.fully_charged));
                break;
            case BatteryManager.BATTERY_STATUS_UNKNOWN:
                setStatusResponse(sr.getString(ai.saiy.android.R.string.currently_indeterminable));
                break;
            default:
                setStatusResponse(sr.getString(ai.saiy.android.R.string.currently_indeterminable));
                break;
        }

        sr.reset();

    } else {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "batteryIntent: null");
        }
        setAccessFailure();
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:61,代码来源:BatteryInformation.java


注:本文中的android.os.BatteryManager.BATTERY_STATUS_UNKNOWN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。