[英]How to notify android app when device is connected with USB port
I'm trying to count how many times mobile has connected with USB port.我正在尝试计算移动设备与 USB 端口连接的次数。 But I don't want to count when the device is connected with USB port only for charging the phone.
但是我不想计算设备何时连接USB端口仅用于为手机充电。 Is there any way to do that in Flutter or Java?
有没有办法在 Flutter 或 Java 中做到这一点?
There is one broadcast event and if you turned on Debug
in your application settings
then you will see a bug on your notification bar when you plugged USB有一个广播事件,如果您在
application settings
打开了Debug
,那么当您插入 USB 时,您会在通知栏上看到一个错误
public void onReceive(Context context, Intent intent) {
String str = intent.getAction();
if (str.equals(UsbManager.ACTION_USB_STATE)) {
Bundle extras = intent.getExtras();
usbConnected = extras.getBoolean(UsbManager.USB_CONNECTED);
...
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.