public void registerUSBBroadcastReceiver() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(UsbManager.ACTION_USB_STATE);
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(UsbManager.ACTION_USB_STATE)) {
Bundle extras = intent.getExtras();
boolean usbConnected = extras.getBoolean(UsbManager.USB_CONNECTED);
if(usbConnected){
Toast.makeText(getApplicationContext(), "usb connected", Toast.LENGTH_SHORT).show();
mIsUsbConnected = true;
}else{
Toast.makeText(getApplicationContext(), "usb disconnected", Toast.LENGTH_SHORT).show();
mIsUsbConnected = false;
}
}
}
};
registerReceiver(mReceiver, intentFilter);
}
'programmer > android' 카테고리의 다른 글
highlighting via keyboad (0) | 2013.07.04 |
---|---|
popupwindow example (0) | 2013.07.03 |
ringtone/alarm tone 설정 (0) | 2013.07.01 |
seekbar progress 위치에 value 표시 (0) | 2013.06.25 |
android custom actionbar (0) | 2013.06.22 |