|
@@ -0,0 +1,25 @@
|
|
1
|
+package com.xhly.manageapp.broadcastreceiver;
|
|
2
|
+
|
|
3
|
+import android.content.BroadcastReceiver;
|
|
4
|
+import android.content.Context;
|
|
5
|
+import android.content.Intent;
|
|
6
|
+import android.hardware.usb.UsbManager;
|
|
7
|
+import android.util.Log;
|
|
8
|
+
|
|
9
|
+public class USBReceiver extends BroadcastReceiver {
|
|
10
|
+ public static final String ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE";
|
|
11
|
+ public static final String USB_FUNCTION_MTP = "mtp";
|
|
12
|
+ public static final String USB_FUNCTION_PTP = "ptp";
|
|
13
|
+ public static final String USB_FUNCTION_ADB = "adb";
|
|
14
|
+ public static final String USB_CONNECTED="connected";
|
|
15
|
+
|
|
16
|
+ @Override
|
|
17
|
+ public void onReceive(Context context, Intent intent) {
|
|
18
|
+
|
|
19
|
+ boolean booleanExtra = intent.getBooleanExtra(USB_CONNECTED, false);
|
|
20
|
+ boolean booleanExtra1 = intent.getBooleanExtra(USB_FUNCTION_MTP, false);
|
|
21
|
+ boolean booleanExtra2 = intent.getBooleanExtra(USB_FUNCTION_PTP, false);
|
|
22
|
+ boolean booleanExtra3 = intent.getBooleanExtra(USB_FUNCTION_ADB, false);
|
|
23
|
+ Log.i("USBReceiver", "获取权限成功:1.链接=="+booleanExtra+",mtp=="+booleanExtra1+",ptp=="+booleanExtra2+",adb=="+booleanExtra3);
|
|
24
|
+ }
|
|
25
|
+}
|