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


Java BatteryManager.BATTERY_STATUS_CHARGING属性代码示例

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


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

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    // 接收电量变化信息
    if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
        int level = intent.getIntExtra("level", 0);
        int scale = intent.getIntExtra("scale", 100);
        // 电量百分比
        int curPower = level * 100 / scale;
        int status = intent.getIntExtra("status", BatteryManager.BATTERY_HEALTH_UNKNOWN);
        // SecondaryProgress 用来展示低电量,Progress 用来展示正常电量
        if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
            mPbBatteryLevel.setSecondaryProgress(0);
            mPbBatteryLevel.setProgress(curPower);
            mPbBatteryLevel.setBackgroundResource(R.mipmap.ic_battery_charging);
        } else if (curPower < BATTERY_LOW_LEVEL) {
            mPbBatteryLevel.setProgress(0);
            mPbBatteryLevel.setSecondaryProgress(curPower);
            mPbBatteryLevel.setBackgroundResource(R.mipmap.ic_battery_red);
        } else {
            mPbBatteryLevel.setSecondaryProgress(0);
            mPbBatteryLevel.setProgress(curPower);
            mPbBatteryLevel.setBackgroundResource(R.mipmap.ic_battery);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:IjkPlayerView.java

示例2: handleBattery

private void handleBattery(Intent intent){
    int level=intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
    int scale=intent.getIntExtra(BatteryManager.EXTRA_SCALE,0);
    int levelPercent = (int)(((float)level / scale) * 100);
    boolean charging = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
            BatteryManager.BATTERY_STATUS_UNKNOWN) == BatteryManager.BATTERY_STATUS_CHARGING;
    if(levelPercent < BATTERY_LOW_LIMIT && !charging)
        AppModel.sDevBatteryLow = true;
    else
        AppModel.sDevBatteryLow = false;
    LogUtils.i("battery:" + level +"%, BatteryLow=" + AppModel.sDevBatteryLow);
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:12,代码来源:XndroidReceiver.java

示例3: getBatteryReading

public  void getBatteryReading(SensorDataListener listener){

        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = context.registerReceiver(null, intentFilter);

        int batteryStatusIntExtra = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = batteryStatusIntExtra == BatteryManager.BATTERY_STATUS_CHARGING ||
                batteryStatusIntExtra == BatteryManager.BATTERY_STATUS_FULL;

        int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
        boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

        int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

        float batteryPct = level / (float)scale;

        Log.i(TAG, "AC connected: "+acCharge);
        Log.i(TAG, "USB connected: "+usbCharge);
        Log.i(TAG, "Battery charging: "+ isCharging);
        Log.i(TAG, "Battery Level: "+ batteryPct);

        ArrayMap<String, String> map = new ArrayMap<>(3);
        map.put(SENSOR, "Battery");
        map.put(VALUE, Integer.toString(level));
        map.put(UNIT, BATTERYSENSOR_UNIT);
        map.put("charging", Boolean.toString(isCharging));
        map.put("acPlugged", Boolean.toString(acCharge));
        map.put("usbPlugged", Boolean.toString(usbCharge));
        listener.sensorData(map);
    }
 
开发者ID:ray0711,项目名称:homeDash,代码行数:32,代码来源:SensorReader.java

示例4: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int alertValue = PreferenceManager.getDefaultSharedPreferences(context).getInt(MainActivity.KEY_BATTERY_PERCENT, 20);

    int status = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    float level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    float scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

    boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_AC;
    float value = (level * 100f) / scale;

    if (!isCharging && (int) value == alertValue) {
        ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(3000);
        Toast.makeText(context, String.format(context.getString(R.string.msg_low_battery), (int) value), Toast.LENGTH_LONG).show();
    }
}
 
开发者ID:TheAndroidMaster,项目名称:BatteryAlert,代码行数:17,代码来源:BatteryReceiver.java

示例5: isPhonePluggedIn

public static boolean isPhonePluggedIn(Context context){
    boolean charging = false;

    final Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    boolean batteryCharge = status==BatteryManager.BATTERY_STATUS_CHARGING;

    int chargePlug = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
    boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

    if (batteryCharge) charging=true;
    if (usbCharge) charging=true;
    if (acCharge) charging=true;

    return charging;
}
 
开发者ID:hanuor,项目名称:sapphire,代码行数:17,代码来源:UploadDocs.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, INVALID);
    int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, INVALID);
    int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, INVALID);
    int source = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, INVALID);
    boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
    String type = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY);
    double temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, INVALID) / 10.0;
    int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, INVALID);

    mBatteryState.setLevel(level);
    mBatteryState.setHealth(health);
    mBatteryState.setCharging(isCharging);
    mBatteryState.setStatus(status);
    mBatteryState.setSource(source);
    mBatteryState.setCapacity(getCapacity());
    mBatteryState.setType(type);
    mBatteryState.setTemperature(temperature);
    mBatteryState.setVoltage(voltage);

    mListener.onBatteryStateChanged(mBatteryState);
}
 
开发者ID:Smart-Studio,项目名称:device-info,代码行数:23,代码来源:BatteryStateProviderImpl.java

示例7: addBatteryStateTo

private void addBatteryStateTo(Collection<IoTDataField> dataFields) {
	IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
	Intent intent = mContext.registerReceiver(null, intentFilter);

	int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
	boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING;
	IoTDataField.BooleanField chargingField = new IoTDataField.BooleanField("charging", isCharging);
	dataFields.add(chargingField);

	int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
	boolean isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
	IoTDataField.BooleanField pluggedField = new IoTDataField.BooleanField("plugged", isPlugged);
	dataFields.add(pluggedField);

	int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
	int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
	float batteryPercent = level / (float) scale;
	// Scale to percents.
	batteryPercent *= 100;
	IoTDataField.IntField batteryPercentField = new IoTDataField.IntField("batteryPrecent", (int) batteryPercent);
	dataFields.add(batteryPercentField);
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:22,代码来源:XmppIotThing.java

示例8: 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

示例9: onReceive

@Override
public void onReceive(BatteryIconData icon, Intent intent) {
    int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 1);
    int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);

    int iconLevel = (int) (((float) level / scale) * 6) + 1;

    if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL)
        iconLevel += 7;

    icon.onDrawableUpdate(iconLevel);

    if (icon.hasText())
        icon.onTextUpdate(String.valueOf((int) (((double) level / scale) * 100)) + "%");
}
 
开发者ID:TheAndroidMaster,项目名称:Status,代码行数:16,代码来源:BatteryIconData.java

示例10: 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

示例11: 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

示例12: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
            BatteryManager.BATTERY_STATUS_UNKNOWN);
    if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
        // 充电中
        mBattery.setImageResource(R.drawable.battery_charging);
    } else if (status == BatteryManager.BATTERY_STATUS_FULL) {
        // 充电完成
        mBattery.setImageResource(R.drawable.battery_full);
    } else {
        int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
        int percentage = (int) (((float) level / scale) * 100);
        if (percentage <= 10) {
            mBattery.setImageResource(R.drawable.battery_10);
        } else if (percentage <= 20) {
            mBattery.setImageResource(R.drawable.battery_20);
        } else if (percentage <= 50) {
            mBattery.setImageResource(R.drawable.battery_50);
        } else if (percentage <= 80) {
            mBattery.setImageResource(R.drawable.battery_80);
        } else if (percentage <= 100) {
            mBattery.setImageResource(R.drawable.battery_100);
        }
    }
}
 
开发者ID:crazysunj,项目名称:CrazyDaily,代码行数:27,代码来源:NeihanVideoPlayerController.java

示例13: setBat

private void setBat(Intent intent) {
        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);

        mIsCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                status == BatteryManager.BATTERY_STATUS_FULL;

//        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

        mBatteryPercent = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);

        Tile battery = getQsTile();

        int resId;

        if (mBatteryPercent >= 95) {
             resId = mIsCharging ? R.drawable.ic_battery_charging_full : R.drawable.ic_battery;
        } else if (mBatteryPercent >= 85) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_90 : R.drawable.ic_battery_90;
        } else if (mBatteryPercent >= 70) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_80 : R.drawable.ic_battery_80;
        } else if (mBatteryPercent >= 55) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_60 : R.drawable.ic_battery_60;
        } else if (mBatteryPercent >= 40) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_50 : R.drawable.ic_battery_50;
        } else if (mBatteryPercent >= 25) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_30 : R.drawable.ic_battery_30;
        } else if (mBatteryPercent >= 15) {
            resId = mIsCharging ? R.drawable.ic_battery_charging_20 : R.drawable.ic_battery_20;
        } else {
            resId = mIsCharging ? R.drawable.ic_battery_charging_20 : R.drawable.ic_battery_alert;
        }

        battery.setIcon(Icon.createWithResource(this, resId));
        battery.setLabel(String.valueOf(mBatteryPercent).concat("%"));
        battery.updateTile();
    }
 
开发者ID:zacharee,项目名称:SystemUITuner2,代码行数:36,代码来源:BatteryTileService.java

示例14: onReceive

public void onReceive(Context context, Intent intent) {
    int pct=
            100 * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 1)
                    / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 1);

    barra_carga.setProgress(pct);
    nivel_carga.setText(String.valueOf(pct) + "%");


    switch (intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)) {
        case BatteryManager.BATTERY_STATUS_CHARGING:
            status_carga.setText("carregando");
            break;

        case BatteryManager.BATTERY_STATUS_FULL:
            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

            if (plugged == BatteryManager.BATTERY_PLUGGED_AC
                    || plugged == BatteryManager.BATTERY_PLUGGED_USB) {
                status_carga.setText("bateria cheia, plugada");
            }
            else {
                status_carga.setText("bateria cheia, mas descarregando");
            }
            break;

        default:
            status_carga.setText("bateria descarregando");
            break;
    }
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:31,代码来源:BateriaActivity.java

示例15: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    boolean charging = status == BatteryManager.BATTERY_STATUS_CHARGING;

    if (charging || !mScreenOn) {
        mLevel = 0;
        mTime = 0;
    } else {
        mCalculating = true;

        long time = System.nanoTime();
        int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);

        if (mLevel != 0 && mLevel > level && mTime != 0 && mTime < time && mLevel - level > 0) {
            long seconds = TimeUnit.SECONDS.convert((time - mTime) / (mLevel - level),
                    TimeUnit.NANOSECONDS);
            if (seconds >= 100) {
                mTimes.add(seconds);

                if (mTimes.size() % 15 == 0) {
                    postCreate(mTimes.toArray(new Long[mTimes.size()]));
                    if (mTimes.size() >= 100) {
                        mTimes.clear();
                    }
                }
            }
        }
        mLevel = level;
        mTime = time;
    }

    mCalculating = false;
}
 
开发者ID:morogoku,项目名称:MTweaks-KernelAdiutorMOD,代码行数:34,代码来源:Monitor.java


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