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


Java BatteryManager.BATTERY_STATUS_FULL属性代码示例

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


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

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

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

示例3: register

@Override
public void register() {
    Intent intent = getContext().registerReceiver(receiver, getIntentFilter());

    if (intent != null) {
        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;

        onDrawableUpdate(iconLevel);

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

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

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

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

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

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

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

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

示例11: isPowerConnected

private static boolean isPowerConnected(Intent batteryStatus) {
    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    boolean isConnected = (status == BatteryManager.BATTERY_STATUS_CHARGING
            || status == BatteryManager.BATTERY_STATUS_FULL);
    Log.d(TAG, "Power connected is " + isConnected);
    return isConnected;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:7,代码来源:OfflinePageUtils.java

示例12: getBatteryStatus

private String getBatteryStatus(Intent intent) {
    // Are we charging / charged?
    int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
    mIsCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
            status == BatteryManager.BATTERY_STATUS_FULL;

    lastTemperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, Integer.MIN_VALUE);
    ReceiverStorage.getInstance().setBatteryTemperature(getLastTemperature());

    // How are we charging?
    int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    ChargingType chargingType = ChargingType.getType(chargePlug);
    String chargeSource = chargingType != null ? chargingType.toString() : botService.getString(R.string.unknown);
    return mIsCharging ? String.format(botService.getString(R.string.charging), chargeSource) : botService.getString(R.string.discharging);
}
 
开发者ID:Rai220,项目名称:Telephoto,代码行数:15,代码来源:BatteryReceiver.java

示例13: doScheduleImmediateNetworkCheck

public boolean doScheduleImmediateNetworkCheck(final Context ctx,
                                               Listener userHandler,
                                               final Constraint constraint1,
                                               final Constraint constraint2) {

    if (userHandler == null) {
        Log.w(TAG, "Invalid argument: Listener object should NOT be null");
        return false;
    }

    MeasureManager.MeasurementCompletedListener internalHandler = null;
    boolean isUserHandlerAlreadyRegistered = false;

    for (MeasureManager.MeasurementCompletedListener mcl : mListenersImmediate.keySet()) {
        if (mListenersImmediate.get(mcl) == userHandler) {
            internalHandler = mcl;
            isUserHandlerAlreadyRegistered = true;
        }
    }

    if (!isUserHandlerAlreadyRegistered) {

        // Create a new internal measurement handler
         internalHandler = new MeasureManager.MeasurementCompletedListener() {
            @Override
            public void onMeasurementComplete(MeasureSample measureSample) {
                boolean isItGoodForVideo = false;
                Log.d(TAG, "Network sampling OK : " + measureSample.testOk
                                        + ", type = " + measureSample.networkType
                                        + ", name = " + measureSample.networkName
                                        + ", quality = " + measureSample.networkState);
                // Rule 1
                if (constraint1 == Constraint.NETWORK_FAST_FOR_MEDIA_DOWNLOAD) {
                    if (measureSample.testOk &&
                            (measureSample.networkState == ConnectionQuality.EXCELLENT || measureSample.networkState == ConnectionQuality.GOOD)) {
                        isItGoodForVideo = true;
                        Log.d(TAG, "Criteria1: Network conditions are good");
                    }
                }
                // Rule 2
                if (constraint2 == Constraint.NETWORK_DEVICE_CHARGING) {
                    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
                    Intent batteryStatus = ctx.registerReceiver(null, ifilter);
                    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
                    boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                            status == BatteryManager.BATTERY_STATUS_FULL;
                    isItGoodForVideo = isItGoodForVideo && isCharging;
                }

                Log.d(TAG, "Final determination: All criteria met? : " + isItGoodForVideo);

                Listener userHandler = mListenersImmediate.get(this);
                if (userHandler != null) {
                    try {
                        // Invoke the user's installed handler with the YES or NO answer
                        // WARN: This method may be slow/time-consuming.
                        userHandler.OnNetworkSuitableForCriteria(isItGoodForVideo);
                    } catch (Exception e) {
                        Log.w(TAG, e.getMessage());
                    }
                }
            }
        };

        // Add it to the map
        mListenersImmediate.put(internalHandler, userHandler);
    }


    MeasureManager manager = MeasureManager.getInstance();
    manager.init(ctx);
    manager.register(internalHandler);
    Log.d(TAG, "Triggering network measurement");
    manager.measureOnce(ctx, "_VID");
    return true;
}
 
开发者ID:fastah,项目名称:network-kit-android,代码行数:76,代码来源:NetworkAwareVideoPreloader.java

示例14: getBatteryLevel

public String getBatteryLevel() {
    if (mBatteryStatus == BatteryManager.BATTERY_STATUS_FULL) {
        return mGbResources.getString(R.string.pie_battery_status_full);
    }
    if (mBatteryStatus == BatteryManager.BATTERY_STATUS_CHARGING) {
        return mGbResources.getString(R.string.pie_battery_status_charging, mBatteryLevel);
    }
    return mGbResources.getString(R.string.pie_battery_status_discharging, mBatteryLevel);
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:9,代码来源:PieController.java

示例15: onReceive

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

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


   mBatteryPercent = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
}
 
开发者ID:irshuLx,项目名称:Android-Wear-Watchface,代码行数:14,代码来源:MyWatchFace.java


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