简体   繁体   English

当设备连接到 USB 端口时如何通知 android 应用程序

[英]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.

相关问题 如何获取USB设备是连接到USB3.0还是USB2.0端口 - How to fetch whether a USB device is connected to USB3.0 or USB2.0 port 如何从USB连接的Android设备读取传感器 - how can I read sensors from an usb connected android device 使用连接到 usb 的设备运行 android - Running android using device connected to usb Usb4Java:连接设备时收听 - Usb4Java:Listen when Device is Connected Android 应用程序在设备上崩溃,但在连接到 android studio 时不会崩溃 - Android app crahses on device but not when connected to android studio 如何找到通过USB连接到android设备的台式机的IP地址 - How to find IP address of desktop pc which is connected to android device through USB 如何通过USB上的串行端口将数据从Android设备发送到PC - How to send data from an Android device to pc through serial port over USB 在没有 USB 的真实设备上测试 android 应用程序 - Testing an android app on real device without USB 如何通过使用模拟器或通过USB连接的设备(例如Android Studio)的android应用程序将文件写入桌面? - How to write files to your desktop with the use of an android application using an emulator or USB-connected device using for example Android Studio? 在Usb主机模式下将数据从android发送到连接的Usb存储设备 - Send data from android to connected Usb storage device in Usb Host Mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM