實例:
package com.AndroidUSB;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidUSBActivity extends Activity {
TextView umsState;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
umsState = (TextView)findViewById(R.id.ums_state);
registerReceiver(receiverUmsConnected, new IntentFilter(Intent.ACTION_UMS_CONNECTED));
registerReceiver(receiverUmsDisConnected, new IntentFilter(Intent.ACTION_UMS_DISCONNECTED));
}
BroadcastReceiver receiverUmsConnected
= new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
umsState.setText("USB Mass Storage Connected");
}};
BroadcastReceiver receiverUmsDisConnected
= new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
umsState.setText("USB Mass Storage Disconnected");
}};
}
沒有留言:
發佈留言