它在以下代码中显示应用程序上的100%电池请帮助解决此问题
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
int l = (level*100)/scale;
Toast.makeText(context,""+l,Toast.LENGTH_LONG).show();
if(l==100)
{
Globalveriable.level = l;
Intent i = new Intent(context, Charged.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
else if(l<100)
{
Globalveriable.level = l;
Intent i = new Intent(context, Battery_screen.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
答案 0 :(得分:0)
使用此代码:
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
Toast.makeText(上下文,&#34;剩余电池:&#34; +级+&#34;%&#34;,Toast.LENGTH_LONG).show();