是否有可能确定一个Android设备是否插入电脑或只是权力? [英] Is it possible to determine whether an Android device is plugged into a computer or just power?

查看:98
本文介绍了是否有可能确定一个Android设备是否插入电脑或只是权力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Android设备被插入电脑或只是权力我想知道是否有可能确定具体。

I was wondering if it was possible to specifically determine if an Android device was plugged into a computer or just power.

主要的原因是我想为我的手机保持清醒,当它插入电脑,而我正在开发,但不能当它插入电源插座一个晚上。

The main reason is I'd like for my phone to "Stay Awake" when it's plugged into a computer while I'm developing, but not when it's plugged into a power outlet a night.

我在想,如果我可以告诉什么,我连接,我可以用ACTION_POWER_CONNECTED启动服务和检查什么USB我连接。

I was thinking that if I could tell what I'm connected to, I could use ACTION_POWER_CONNECTED to start up a service and check what USB I'm connected to.

推荐答案

我居然发现选择是否通过查看源以保持当插入AC,USB或放在画面<确切的方式href=\"http://google.com/$c$csearch#409TP6F96yI/src/com/android/settings/DevelopmentSettings.java&l=95\" rel=\"nofollow\">http://google.com/$c$csearch#409TP6F96yI/src/com/android/settings/DevelopmentSettings.java&l=95

I actually found the exact way to choose whether to keep the screen on when plugged into AC, USB or either by looking into the source at http://google.com/codesearch#409TP6F96yI/src/com/android/settings/DevelopmentSettings.java&l=95

需要的权限: android.permission.WRITE_SETTINGS

Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN,
                mKeepScreenOn.isChecked() ?
                (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);

有关AC: BatteryManager.BATTERY_PLUGGED_AC

有关USB: BatteryManager.BATTERY_PLUGGED_USB

对于任何一个:(BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB)

这篇关于是否有可能确定一个Android设备是否插入电脑或只是权力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆