當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。