如何按命令打开平板电脑屏幕?

时间:2016-08-17 00:21:07

标签: android tablet

我想让我的三星Galaxy tab 3 t111屏幕只有在连接到microUSB时才能永久打开。试图制作汽车导航。

1 个答案:

答案 0 :(得分:0)

我没有对此进行测试,但它应该可行。如果没有,它会让你朝着正确的方向前进。

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //battery receiver setup
        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = context.registerReceiver(null, ifilter);

        // Are we charging / charged?
        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                     status == BatteryManager.BATTERY_STATUS_FULL;

        if(isCharging) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    }
}