我正在为Android平板电脑开发android应用程序,我尝试在设备充电连接打开设备时这样做。是否可以在连接充电时自动启动Android设备?
答案 0 :(得分:1)
这取决于它是哪个设备。基本上,您需要使用Shell脚本更新电池加载动画文件以重新启动设备,但是您必须知道哪个文件负责使电池图标动画化。每个OEM都有自己的命名/定位动画文件的标准,您应该找到自己的标准。
答案 1 :(得分:0)
First of all you have to register broadcast receiver for `ACTION_BATTERY_CHANGED ':
BroadcastReceiver PowerStatusReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Intent batteryStatus = context.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
assert batteryStatus != null;
status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
and you will have 2 options:
if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL) {
// device plugged
// ...
}else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
// device unplugged
// ...
}
and:
IntentFilter powerConnectedFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(PowerStatusReceiver, powerConnectedFilter);
And to keep the screen on while the device is plugged, see: Android Keep Screen On In App
Good luck :)