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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| package com.example.a28012014;
import java.util.HashMap;
import java.util.Iterator;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@SuppressLint("NewApi")
public class MainActivity extends Activity {
private String LOG_TAG;
TextView heure = null;
Button Button01= null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
Button01 = (Button)findViewById(R.id.button01);
Button01.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
try {
Log.i(LOG_TAG,"USB HOST");
UsbManager usbManager=(UsbManager)getSystemService(USB_SERVICE);
HashMap<String,UsbDevice> deviceList=usbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator=deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device=deviceIterator.next();
heure= (TextView) findViewById(R.id.heure);
heure.setText(Log.i(LOG_TAG, "MOdel"+device.getDeviceName())+
Log.i(LOG_TAG, "id"+device.getDeviceId())+
Log.i(LOG_TAG, "Class"+device.getDeviceClass())+
Log.i(LOG_TAG, "Protocol"+device.getDeviceProtocol())+
Log.i(LOG_TAG, "Protocol"+device.getDeviceProtocol())+
Log.i(LOG_TAG, "VendorId"+device.getVendorId())+
Log.i(LOG_TAG, "ProductId"+device.getProductId())+
Log.i(LOG_TAG, "---------------------------------"));
heure= (TextView) findViewById(R.id.heure);
heure.setText("error");
}
}
catch(Exception e){
Log.e(LOG_TAG, e.getMessage());
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
} |
Partager