当前位置:首页 » 安卓系统 » android系统电量

android系统电量

发布时间: 2023-01-06 21:08:21

Ⅰ android操作系统怎么获得电量

这个是获取电量的android DEMO:
package com.android.batterywaster;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import java.text.DateFormat;
import java.util.Date;

/**
* So you thought sync used up your battery life.
*/
public class BatteryWaster extends Activity {
TextView mLog;
DateFormat mDateFormat;
IntentFilter mFilter;
PowerManager.WakeLock mWakeLock;
SpinThread mThread;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set the layout for this activity. You can find it
// in res/layout/hello_activity.xml
setContentView(R.layout.main);

findViewById(R.id.checkbox).setOnClickListener(mClickListener);
mLog = (TextView)findViewById(R.id.log);

mDateFormat = DateFormat.getInstance();

mFilter = new IntentFilter();
mFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
mFilter.addAction(Intent.ACTION_BATTERY_LOW);
mFilter.addAction(Intent.ACTION_BATTERY_OKAY);
mFilter.addAction(Intent.ACTION_POWER_CONNECTED);

PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "BatteryWaster");
mWakeLock.setReferenceCounted(false);
}

@Override
public void onPause() {
stopRunning();
}

View.OnClickListener mClickListener = new View.OnClickListener() {
public void onClick(View v) {
CheckBox checkbox = (CheckBox)v;
if (checkbox.isChecked()) {
startRunning();
} else {
stopRunning();
}
}
};

void startRunning() {
log("Start");
registerReceiver(mReceiver, mFilter);
mWakeLock.acquire();
if (mThread == null) {
mThread = new SpinThread();
mThread.start();
}
}

void stopRunning() {
log("Stop");
unregisterReceiver(mReceiver);
mWakeLock.release();
if (mThread != null) {
mThread.quit();
mThread = null;
}
}

void log(String s) {
mLog.setText(mLog.getText() + "\n" + mDateFormat.format(new Date()) + ": " + s);
}

BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String title = action;
int index = title.lastIndexOf('.');
if (index >= 0) {
title = title.substring(index + 1);
}
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int icon = intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL,-1);
log(title + ": level=" + level + "\n" + "icon:" + icon);
} else {
log(title);
}
}
};

class SpinThread extends Thread {
private boolean mStop;

public void quit() {
synchronized (this) {
mStop = true;
}
}

public void run() {
while (true) {
synchronized (this) {
if (mStop) {
return;
}
}
}
}
}
}
这个是layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>

<CheckBox android:id="@+id/checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:textSize="18sp"
android:textColor="#ffffffff"
android:text="@string/waste_away"
/>

<ScrollView android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
>
<TextView android:id="@+id/log"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:textSize="12sp"
android:textColor="#ffffffff"
/>
</ScrollView>

</LinearLayout>

Ⅱ android系统耗电量70%怎么解决

你手机剩下多少电?如果机子一整天待机的话,用3%-5%电的话,那么android系统耗电占70%很正常,除非你关机,不然一整天开着手机系统运行一整天耗电占最大很正常,除非你玩手机,这样屏幕耗电就是最大的了

Ⅲ oppoa51 android系统费电量达30%多

手机耗电是和个人的使用习惯关系非常大。一般手机正常拨打电话和待机的时间一般在一天左右。建议您可以在手机自带的自启动管理中关闭无需自启动的程序。建议在您晚上睡觉的时候开启飞行模式,如果一个晚上(8个小时)手机的耗电量超过5%,建议...

Ⅳ 手机android系统耗电快怎么办!

手机android系统耗电快解决办法:

方法一

数据没有关闭,在使用的过程中,上网之后,网络数据或者WiFi一直没有关闭,因此导致还在后台运行着。所以还是需要花费的电量。所以建议,停用数据的时候,就顺手把数据关闭掉,不然不仅流量还在消耗,而且电量也在流失。

Ⅳ 三星手机 Android操作系统为什么耗电量那么大如何省电

三星手机正常待机时间大约1-2天左右。手机待机时长与电池容量、个人使用习惯、网络质量等有关。如上网、看视频、玩游戏等相对比较耗电。以下为您提供几种延长手机待机时间的方法,请您参考:
1.蓝牙、WLAN、GPS、照相机、浏览器等相关应用程序,这些功能使用完成后建议您及时关闭。
2.开启手机的省电模式或者超级省电模式。
3.减少背景灯时间。
4.调低显示屏的亮度。

热点内容
服务器404代表什么 发布:2025-05-17 06:39:51 浏览:559
我的世界龙蛋服务器 发布:2025-05-17 06:20:06 浏览:912
安卓系统软件怎么不更新 发布:2025-05-17 06:19:15 浏览:817
安卓夏日传说存档放哪个文件 发布:2025-05-17 06:12:44 浏览:606
如何通过服务器id找到主人 发布:2025-05-17 06:12:11 浏览:37
ug编程吧 发布:2025-05-17 06:07:45 浏览:72
sql临时表和表变量 发布:2025-05-17 06:02:38 浏览:724
苹果如何用安卓无线耳机 发布:2025-05-17 06:01:53 浏览:822
sqlserver表关系 发布:2025-05-17 06:01:02 浏览:997
2017途观配置什么音响 发布:2025-05-17 05:53:50 浏览:844