当我使用BatteryStatsHelper获取应用程序电池信息时,我已设置权限" android.permission.BATTERY_STATS",但系统说我没有获得许可。
Caused by: java.lang.SecurityException: uid 10164 does not have android.permission.BATTERY_STATS.
答案 0 :(得分:0)
在这里尝试这样的东西并摆脱Batstat方法。 点击此处http://www.tutorialforandroid.com/2009/01/getting-battery-information-on-android.html
这应该为您提供监控战斗所需的所有信息。
public class Main extends Activity {
private TextView batteryTxt;
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context ctxt, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
batteryTxt.setText(String.valueOf(level) + "%");
}
};
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
batteryTxt = (TextView) this.findViewById(R.id.batteryTxt);
this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
}