forked from maniero/SOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsbDetect.java
More file actions
34 lines (33 loc) · 1.55 KB
/
Copy pathUsbDetect.java
File metadata and controls
34 lines (33 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class DetactUSB extends BroadcastReceiver {
private static final String TAG = "DetactUSB";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_CONNECTED")) {
TextView textView = new TextView(context);
textView.setBackgroundColor(Color.MAGENTA);
textView.setTextColor(Color.BLUE);
textView.setPadding(10,10,10,10);
textView.setText("USB connected……….");
Toast toastView = new Toast(context);
toastView.setDuration(Toast.LENGTH_LONG);
toastView.setGravity(Gravity.CENTER, 0,0);
toastView.setView(textView);
toastView.show();
Log.i(TAG,"USB connected..");
}
if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_DISCONNECTED")) {
TextView textView = new TextView(context);
textView.setBackgroundColor(Color.MAGENTA);
textView.setTextColor(Color.BLUE);
textView.setPadding(10,10,10,10);
textView.setText("USB Disconnected……….");
Toast toastView = new Toast(context);
toastView.setDuration(Toast.LENGTH_LONG);
toastView.setGravity(Gravity.CENTER, 0,0);
toastView.setView(textView);
toastView.show();
}
}
}
//https://pt.stackoverflow.com/q/45400/101