Developers.android.com 코드의 도움으로 샘플 앱을 개발해 보았습니다. 내가 연결된 USB 장치에이 코드를 실행하면USB 호스트로 작동하는 Android 태블릿에서 USB 장치를 검색하는 방법은 무엇입니까?
내 코드는 항상 "장치를 찾을 수 없음"으로 토스트를 얻을이
public class MainActivity extends Activity {
UsbManager manager;
HashMap<String, UsbDevice> deviceList;
Button scanButton;
UsbDevice device;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanButton = (Button)this.findViewById(R.id.button1);
scanButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
checkForDevices();
}
});
}
@Override
public void onResume()
{
super.onResume();
checkForDevices();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
protected void checkForDevices()
{
manager = (UsbManager) getSystemService(Context.USB_SERVICE);
deviceList = manager.getDeviceList();
device = deviceList.get("deviceName");
//Collection<UsbDevice> devices = deviceList.values();
if (device != null)
Toast.makeText(this, "Device Found", Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Device NOT Found", Toast.LENGTH_LONG).show();
}
}
것 같습니다.
내 응용 프로그램이 USB 장치를 감지하고 USB 호스트 모드에서 입력 읽기 및 출력 쓰기를 원합니다.
앱에서 USB 장치를 감지 할 수있는 방법이 있습니까?
가능한 중복 된 작업에 대한 좋은 예이다 here 될 것이라고 ] (http://stackoverflow.com/questions/3803871/android-apps-communicating-with-a-device-plugged-in-the-usb-port) – ale