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


Java Intent.ACTION_BATTERY_CHANGED属性代码示例

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


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

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    try {
        String action = intent.getAction();
        if(action == Intent.ACTION_BATTERY_CHANGED){
            handleBattery(intent);
        }else if(action == ConnectivityManager.CONNECTIVITY_ACTION){
            AppModel.getNetworkState();
        }else if(action == Intent.ACTION_SCREEN_ON){
            AppModel.sDevScreenOff = false;
            LogUtils.i("screen on");
        }else if(action == Intent.ACTION_SCREEN_OFF){
            AppModel.sDevScreenOff = true;
            LogUtils.i("screen off");
        }
    }catch (Exception e){
        LogUtils.e("onReceive error ", e);
    }

}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:20,代码来源:XndroidReceiver.java

示例2: setCharging

@SuppressWarnings("deprecation")
public static void setCharging(Context context, boolean charging) {
    Intent chargingIntent = new Intent(Intent.ACTION_BATTERY_CHANGED);
    if (charging) {
        chargingIntent.putExtra(BatteryManager.EXTRA_PLUGGED, BatteryManager.BATTERY_PLUGGED_AC);
    }
    context.sendStickyBroadcast(chargingIntent);
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:8,代码来源:DeviceTestUtils.java

示例3: create

/**
 * Create a PowerMonitor instance if none exists.
 * @param context The context to register broadcast receivers for.  The application context
 *                will be used from this parameter.
 */
public static void create(Context context) {
    context = context.getApplicationContext();
    if (sInstance == null) {
        sInstance = LazyHolder.INSTANCE;
        ApplicationStatus.registerApplicationStateListener(sInstance);
        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatusIntent = context.registerReceiver(null, ifilter);
        if (batteryStatusIntent != null) onBatteryChargingChanged(batteryStatusIntent);
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:15,代码来源:PowerMonitor.java

示例4: onResume

protected void onResume() {
	super.onResume();

	updateMemoryStatus();

	// register common receiver
	IntentFilter filter = mCommonIntentFilter;
	if (filter == null) {
		filter = mCommonIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
		filter.addAction(LedFlashlightReceiver.ACTION_FLASHLIGHT);
		mCommonIntentReceiver = new CommonIntentReceiver();
	}
	registerReceiver(mCommonIntentReceiver, filter);

	// create/initialize/activate handlers
	createInitializeActivateHandlers();
	mLayout.updateLayout(this);
	updateFlashlightView();

	if (mRestartRequired) {
		finish();
		Intent intent = new Intent(Constants.ACTION_START_QS);
		sendBroadcast(intent);
	}
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:25,代码来源:MainSettingsActivity.java

示例5: batteryLevelUpdater

private void batteryLevelUpdater()
{
    batteryLevelReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            //context.unregisterReceiver(this);
            int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            int level = -1;
            if (rawlevel >= 0 && scale > 0) {
                level = (rawlevel * 100) / scale;
            }
            mBatteryLevelView.setLevel(level);
        }
    };
    batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(batteryLevelReceiver, batteryLevelFilter);
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:17,代码来源:Main.java

示例6: battery

/**
 * 获取手机剩余电量
 * 
 * @return
 */
private static String battery() {
	IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
	Intent intent = NimUIKit.getContext().registerReceiver(null, filter);
	int level = intent.getIntExtra("level", -1);
	int scale = intent.getIntExtra("scale", -1);
	if(scale == -1) {
		return "--";
	} else {
		return String.format(Locale.US, "%d %%", (level*100) / scale);
	}
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:16,代码来源:CrashSnapshot.java

示例7: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction() == Intent.ACTION_BATTERY_CHANGED) {
        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
        int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
        float temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)) / 10;
        float chargeLevel = ((float) (level * 100)) / scale;

        for (SensorInfo sensorInfo : sensorInfos) {
            if (sensorInfo.getType() == SensorType.BATTERY) {
                sensorInfo.setValues(new float[]{temperature, chargeLevel});
                break;
            }
        }
    }
}
 
开发者ID:SKT-ThingPlug,项目名称:thingplug-sdk-android,代码行数:16,代码来源:SensorListener.java

示例8: recordBatteryLevel

private void recordBatteryLevel() {
    Log.i(TAG, "Record battery level");

    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = mContext.registerReceiver(null, ifilter);

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

    float batteryPct = (level / (float) scale) * 100;
    mTelemetry.write(Telemetry.BATTERY_TAG, String.valueOf(batteryPct));
}
 
开发者ID:rofferom,项目名称:gpstracker-android,代码行数:12,代码来源:BatteryRecorder.java

示例9: onStart

@Override
protected void onStart() {
    super.onStart();
    IntentFilter f=new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(onBattery, f);

}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:7,代码来源:BateriaActivity.java

示例10: getBatteryPercent

private float getBatteryPercent() {
    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    Intent batteryStatus = RYLA.getInstance().getContext().registerReceiver(null, ifilter);

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

    return level / (float)scale * 100;
}
 
开发者ID:TeamThresh,项目名称:Lantern-sdk,代码行数:9,代码来源:RylaInstrumentation.java

示例11: registerBatteryUpdates

private Intent registerBatteryUpdates(Context context) {
  IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  return context.registerReceiver(null, filter);
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:4,代码来源:MapEventFactory.java

示例12: getDeviceConditionsImpl

/** Returns the current device conditions. May be overridden for testing. */
protected DeviceConditions getDeviceConditionsImpl(Context context) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    // Note this is a sticky intent, so we aren't really registering a receiver, just getting
    // the sticky intent.  That means that we don't need to unregister the filter later.
    Intent batteryStatus = context.registerReceiver(null, filter);
    if (batteryStatus == null) return null;

    // Get the connection type from chromium's internal object.
    int connectionType = NetworkChangeNotifier.getInstance().getCurrentConnectionType();

    // Sometimes the NetworkConnectionNotifier lags the actual connection type, especially when
    // the GCM NM wakes us from doze state.  If we are really connected, report the connection
    // type from android.
    if (connectionType == ConnectionType.CONNECTION_NONE) {
        // Get the connection type from android in case chromium's type is not yet set.
        ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
        if (isConnected) {
            connectionType = convertAndroidNetworkTypeToConnectionType(activeNetwork.getType());
        }
    }

    return new DeviceConditions(
            isPowerConnected(batteryStatus), batteryPercentage(batteryStatus), connectionType);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:28,代码来源:OfflinePageUtils.java

示例13: start

@Override
public void start() {
    if(!isRegistered) {
        isRegistered = true;
        IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        application.registerReceiver(batteryReceiver, filter);

        if(informationPlugin != null) {
            CmdArg cmd = new CmdArg(0, "Registered Battery.");
            informationPlugin.sendReplyCommand(PluginService.INFORMATION, cmd);
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:13,代码来源:BatteryPresenter.java

示例14: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String message = null;
    switch (intent.getAction()) {
        case Intent.ACTION_BATTERY_LOW:
            if (!isSentBatteryLow) {
                message = botService.getString(R.string.battery_low);
                isSentBatteryLow = true;
            }
            break;
        case Intent.ACTION_BATTERY_OKAY:
            isSentBatteryLow = false;
            break;
        case Intent.ACTION_POWER_DISCONNECTED:
            message = botService.getString(R.string.power_disconnected) + getStatus();
            break;
        case Intent.ACTION_POWER_CONNECTED:
            message = botService.getString(R.string.power_connected);
            break;
        case Intent.ACTION_BATTERY_CHANGED:
            mBatteryLevel = getBatteryLevel(intent);
            mPowerStatus = getBatteryStatus(intent);
            ReceiverStorage.getInstance().setBatteryLevel(mBatteryLevel);
            int segment = getSegment(mBatteryLevel);
            if (segment < lastSegmentNotify) {
                String attention = mIsCharging ? botService.getString(R.string.battery_discharging) : "";
                message = attention + getStatus();
            }
            lastSegmentNotify = segment;
            break;
    }
    if (message != null) {
        botService.getTelegramService().sendMessageToAll(message);
    }
}
 
开发者ID:Rai220,项目名称:Telephoto,代码行数:35,代码来源:BatteryReceiver.java

示例15: initBatteryReceiver

private void initBatteryReceiver(Context context) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    batteryReceiver = new BatteryReceiver();
    if(context!=null){
        context.registerReceiver(batteryReceiver,filter);
    }
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:7,代码来源:DefaultPlayerControllerCover.java


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