I am new to android programming, my main aim is to communicate over USB to an MCU using FT200XD USB to I2C bridge.
First I am trying to detect attached USB device via the UsbManager. From what I understand, at on create a popup window should ask permission to connect from the user but no permission is asked. While debugging its clear that the control doesn't go into the broadcast receiver section.
I have refereed few example code snippet and wrote the code below. I don't know what I am doing wrong.
I have downloaded an app called"USB host Controller" which does detect the FT200XD. Which means my tablet has the USB host functionality. It will be great if you can point me to the right direction or an entire working code can be shared.
My code is as follows:
Java file:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
mPermissionIntent= PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(UsbManager.EXTRA_PERMISSION_GRANTED);
filter.addAction(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
}
// Broadcast receiver
public class mUsbReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(),
"Inside USB Broadcast", Toast.LENGTH_SHORT).show();
}
}
Manifest file part:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.usb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.usb.host" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name="mUsbReceiver">
<intent-filter>
<action android:name="android.hardware.usb.action.ACTION_USB_PERMISSION"/>
</intent-filter>
</receiver>
<activity
android:name="com.example.usb.FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter" />
</activity>
</application>
</manifest>
Device_filter.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 0x0403 / 0x6001: FTDI FT232R UART -->
<usb-device vendor-id="1027" product-id="24577" />
<!-- 0x2341 / Arduino -->
<usb-device vendor-id="9025" />
<!-- 0x16C0 / 0x0483: Teensyduino -->
<usb-device vendor-id="5824" product-id="1155" />
<!-- 0x617 / 0x000b: EFPL CC2531 -->
<usb-device vendor-id="1559" product-id="11" />
<!-- vendor-id="0x0403" product-id="0x6015" // converted to Int vendor ID and product ID of my FT200XD-->
<usb-device vendor-id="1027" product-id="24597" />
</resources>
You probably want to look at the return code for registerReceiver - from what you are posting in your code I'd assume it would be failing since you don't actually instantiate your mUsbReceiver. Take a look at this code, which is from extracted from an application I've written that works, notice the difference in the way I'm setting up my BroadcastReceiver, this also shows how to request permission if your device is inserted:
PendingIntent mPermissionIntent = null;
UsbManager mUsbManager = null;
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
UsbDevice usbDevice = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (ACTION_USB_PERMISSION.equals(action)) {
// Permission requested
synchronized (this) {
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
// User has granted permission
// ... Setup your UsbDeviceConnection via mUsbManager.openDevice(usbDevice) ...
} else {
// User has denied permission
}
}
}
if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
// Device removed
synchronized (this) {
// ... Check to see if usbDevice is yours and cleanup ...
}
}
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
// Device attached
synchronized (this) {
// Qualify the new device to suit your needs and request permission
if ((usbDevice.getVendorId() == MY_VID) && (usbDevice.getProductId() == MY_PID)) {
mUsbManager.requestPermission(usbDevice, mPermissionIntent);
}
}
}
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
// ... App Specific Setup Here ...
mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
// Register an intent filter so we can get permission to connect
// to the device and get device attached/removed messages
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mUsbReceiver, filter);
// ... More App Specific Setup ...
}
Also - it appears that for my app I did not need the extra intent-filter or meta-data XML for the USB actions.
Related
This question already has answers here:
How to use NFC ACTIONS
(5 answers)
Closed 3 years ago.
I'm creating application that do some action if hit NFC chip , I know the following information about NFC in Android please correct me if I am wrong
you can't register actions of the NFC to receiver in the manifest file , only activities .
each NFC chip has it's own unique id .
what I want to do is
while the Application is in the background or it's closed , if I hit NFC chip with id (ex 1234) my app lunched and do some action.
is that possible ?
if yes, how it can be achieved?
edit
here is my code , it does open when you check any NFC chip and get this action android.nfc.action.TECH_DISCOVERED
but when it open the action is android.intent.action.MAIN
MainActivity.java
public class MainActivity extends AppCompatActivity {
public static final String ACTION_CHECK_IN= "checked";
public static final String ACTION_CHECK_OUT= "unchecked";
private NfcAdapter mNfcAdapter;
boolean isCheckedIn = false;
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
isCheckedIn = Pref.getBoolean("check", false);
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume() called with: " + "");
String action = getIntent().getAction();
if (action != null) {
Log.d("MainActivity", "onCreate(" + action + ")");
if (action.equals(NfcAdapter.ACTION_NDEF_DISCOVERED) || action.equals(NfcAdapter.ACTION_TAG_DISCOVERED) || action.equals(NfcAdapter.ACTION_TECH_DISCOVERED)) {
if (!isCheckedIn) {
isCheckedIn = true;
Pref.putBoolean("check", true);
Log.d("checking","IN");
} else {
isCheckedIn = false;
Pref.putBoolean("check", false);
Log.d("checking","Out");
}
}
}
if (!mNfcAdapter.isEnabled()) {
Toast.makeText(MainActivity.this, "Please open it ", Toast.LENGTH_SHORT).show();
}
/**
* It's important, that the activity is in the foreground.
* Otherwise an IllegalStateException is thrown.
*/
setupForegroundDispatch(this, mNfcAdapter);
}
#Override
protected void onPause() {
/**
* Call this before onPause, otherwise an IllegalArgumentException is thrown.
*/
stopForegroundDispatch(this, mNfcAdapter);
super.onPause();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
public static void setupForegroundDispatch(Activity activity, NfcAdapter adapter) {
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(
activity.getApplicationContext(), 0, intent, 0);
IntentFilter[] filters = new IntentFilter[2];
String[][] techList = new String[][]{};
// same filter as manifest - action, category
filters[0] = new IntentFilter();
filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
filters[1] = new IntentFilter();
filters[1].addAction(NfcAdapter.ACTION_TECH_DISCOVERED);
adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
public static void stopForegroundDispatch(Activity activity, NfcAdapter adapter) {
adapter.disableForegroundDispatch(activity);
}
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.srjo.pocnfcadapter">
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/filter_nfc" />
</activity>
</application>
</manifest>
According the the Android Developer site, it is possible for your app to filter NFC intents such as ACTION_NDEF_DISCOVERED.
First register your app in the manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.survivingwithandroid.nfc" >
....
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
<manifest>
Then you should use foreground dispatch (foreground app). Finally you use NFCAdapter to read the content (onNewIntent).
I wrote a detailed posts about NFC if you like give a look.
I'm messing about with the USB host, and following the guidelines on the Android Developers site I've managed to create a Hello World that starts up once a particular USB device is plugged in. However, when I try and "...obtain the UsbDevice that represents the attached device from the intent" it returns null:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent();
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
// device is always null
if (device == null){Log.i(TAG,"Null device");}
Here's my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.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" android:resource="#xml/device_filter" />
</activity>
</application>
And my xml/device_filter.xml (I know these are the correct VID and PID because I've got a similar app working using the enumeration method described on the Android Developers site):
<resources>
<usb-device vendor-id="1234" product-id="1234"/>
</resources>
When your application is (re-)started due to the USB device attach event, then the device is passed on to the intent when onResume is called. You can get to it using the getParcelableExtra method. For example:
#Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null) {
Log.d("onResume", "intent: " + intent.toString());
if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (usbDevice != null) {
Log.d("onResume", "USB device attached: name: " + usbDevice.getDeviceName());
I found a workaround (or the intended usage?) thanks to Taylor Alexander. Basically, The way I understand it is that firing the intent that opens the application only opens the application. After that you have to search for and access usb devices as per the Enumerating Devices section of the Android Developers page in the onResume method.
#Override
public void onResume() {
super.onResume();
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
// Your code here!
}
I'm not convinced this is the RIGHT way to do it, but it seems to be working. If anyone has any further suggestions I'd be glad to listen.
I am coding an USB host App recently, but it's stucked because I can't detect the device attached/detached event, I followed the coding note of http://developer.android.com/guide/topics/connectivity/usb/host.html and refer to other's coding in the network, After checking several times, I still can't find the problem. After my debugging, it seems that the UsbManager.ACTION_USB_DEVICE_ATTACHED/UsbManager.ACTION_USB_DEVICE_DETACHED intent is not happened, Because I try to use Context.sendBroadcast() to send a customized Intent, and my BroadcastReceiver can receive the intent. But when I attach/detach the USB device, the BroadcastReceiver don't run. The cellphone I use is HTC One-X, I am sure the OTG function is correct as the mouse function working perfectly.
Here is my code piece.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launcher);
mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
if(mUsbManager == null) {
Log.d(TAG, "mUsbManager is null");
}
// listen for new devices
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
// filter.addAction("MyTest");
registerReceiver(mUsbReceiver, filter);
}
The BroadcastReceiver
BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "mUsbReceiver.onReceive start");
String action = intent.getAction();
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
setDevice(device);
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
if (mDevice != null && mDevice.equals(device)) {
setDevice(null);
}
}
}
};
Manifest.xml
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-sdk android:minSdkVersion="12" />
<application>
<activity android:name=".USBActivity"
android:label="USBActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <receiver android:name=".mUsbReceiver"> -->
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter" />
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="#xml/device_filter" />
<!-- </receiver> -->
</activity>
</application>
device_filter in res/xml, all 3 settings are tried and no-use:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- iCooby mouse -->
<!-- <usb-device vendor-id="15d9" , /> -->
<!-- <usb-device vendor-id="5593" product-id="2637"/> -->
<usb-device />
</resources>
If someone know what's happened? or tell me how to detect if the broadcast intent is active or not, thanks very much.
Perhaps a bit late, but it may help others. Just solved a similar problem with detecting the insertion of USB devices. It turns out that - because you specified an intent filter in the manifest - Android calls onResume when something is plugged in. You might try adding this:
#Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null) {
Log.d("onResume", "intent: " + intent.toString());
if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
// Do your thing ...
}
Then you also do not need the registerReceiver() call in onCreate(). Please also keep in mind that the ID's in the intent filter are in decimal. So you would have to convert the values as presented by command line tools like 'lsusb'.
The receiver tag is commented out, I'm guessing you know that but just incase. Also it should be declared as <receiver android:name="mUsbReceiver"> yours has a '.' which doesn't need to be there
I've written a simple app to send commands to a USB printer connected to an Android 4.0 tablet via USB. For some reason, I am unable to get past obtaining permissions to claim an interface and open a connection. Here's the relevant code :
public class TestPrintActivity extends Activity {
private UsbManager mUsbManager;
private UsbDevice mDevice;
private UsbDeviceConnection mConnection;
private UsbInterface mInterface;
private UsbEndpoint mBulkIn;
private UsbEndpoint mBulkOut;
private static final String ACTION_USB_PERMISSION =
"com.demo.xprinter.USB_PERMISSION";
private PendingIntent mPermissionIntent;
private BroadcastReceiver mUsbReceiver;
#Override
private static final String ACTION_USB_PERMISSION =
"com.demo.printerDemo.USB_PERMISSION";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_print);
mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
registerReceiver(mUsbReceiver, filter);
mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if(device != null){
//call method to set up device communication
openPort(device);
}
}
else {
Toast.makeText(getApplicationContext(), "Denied!", Toast.LENGTH_SHORT).show();
}
}
}
}
};
}
public void onResume() {
super.onResume();
HashMap<String,UsbDevice> deviceList = mUsbManager.getDeviceList();
for (HashMap.Entry<String,UsbDevice> entry : deviceList.entrySet()) {
UsbDevice aDevice = entry.getValue();
if ((aDevice.getProductId() == 8965) && (aDevice.getVendorId() == 1659) ){
if (mUsbManager.hasPermission(aDevice))
openPort(aDevice);
else
mUsbManager.requestPermission(aDevice, mPermissionIntent);
break;
}
}
}
Here's the relevant part of the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo.printerDemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-feature android:name="android.hardware.usb.host"/>
I've configured the device so that it launches my app whenever the printer is connected, and the device is found during the enumeration (onResume()) and the request for permission is called. However, for whatever reason, I never see the "Request Permission" dialog (I've seen screenshots of it online) nor does onReceive() ever get called. Any ideas why this might be happening?
1) Why do you have two members ACTION_USB_PERMISSION declared?
2) In onCreate() try to register your Intent like this, maybe there is a difference:
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(ACTION_USB_PERMISSION);
context.registerReceiver(usbReceiver, filter);
3) Due to a bug in Android (http://code.google.com/p/android/issues/detail?id=25703), I'm not sure if ACTION_USB_ACCESSORY_ATTACHED action is ever called. Try to add the below in your AndroidManifest.xml:
<activity ...>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="#xml/device_filter"/>
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So it turns out that SystemUI.apk/SystemUI.odex in /system/ had been change to SystemUI.apk.backup/SystemUI.odex.backup respectively. This presumably was to prevent some aspects of the System UI from mucking up the intended "kiosk" mode of the device. The logcat entry in my previous comment was the big clue. Once the filenames were restored, I started seeing the Permission dialog.
I have USB host android device for that I need to connect USB device. to detect usb device to host I written following code.
public class ReadData extends Activity {
UsbManager usbManager;
PendingIntent mPermissionIntent;
UsbDevice usbDevice;
Intent intent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_data);
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
final String ACTION_USB_PERMISSION =
"com.example.udevice.USB_PERMISSION";
IntentFilter filter = new IntentFilter("android.hardware.usb.action.USB_ACCESSORY_ATTACHED");
registerReceiver(mUsbReceiver, filter);
}
private static final String ACTION_USB_PERMISSION =
"com.example.udevice.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
usbManager.requestPermission(usbDevice, mPermissionIntent);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if(usbDevice != null){
//call method to set up device communication
int deviceId = usbDevice.getDeviceId();
int productId = usbDevice.getProductId();
Log.i("device id", "****"+deviceId);
Log.i("product id", "****"+productId);
}else{
Log.i("device id", "No USB device");
}
}
else {
Log.d("shiv", "permission denied for device ");
}
}
}
}
};
and manifest is like below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.udevice"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".ReadData"
android:label="#string/title_activity_heat_con" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter" />
</activity>
</application>
</manifest>
device_filter.xml
<resources>
<usb-device vendor-id="67b"
product-id="2303"/>
</resources>
in above xml file I added device attributes. I am expecting a broadcast intent whenever USB device connected to host device. but it is not happening. What is wrong with above code.
Thanks
shiv
I think you need to add:
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
It is described here
There is onething you are doing it wrong.
The vendor id and device id should be in decimals not in hex. For example, you need to define as follows
<resources>
<usb-device vendor-id="1659"
product-id="8963"/>
</resources>
I converted your device id and vendor-id from hex to decimal
Let me know if this helps