erreur lors de la demarrage
pourquoi ce code ne fonctionne pas
Code:
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;
}
} |
activity main
Code:
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
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/heure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button01"
android:layout_marginTop="55dp"
android:layout_toRightOf="@+id/button01"
android:text="affiche" />
</RelativeLayout> |
android manifest
Code:
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
|
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a28012014"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.a28012014.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
/>
</activity>
</application>
</manifest> |