Working in Samsung S4 device, but not working in MotoG, Samsung A5(2016)
Below Code always return zero, I tried with giving permission in manifest file but still it returns null.. Can anyone give me any suggestion
In the Activity code:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
HashMap<String, UsbDevice> devicelist = usbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = devicelist.values().iterator();
Log.i("List", "size =" + devicelist.size());
Log.i("List", "List" + devicelist);
while(deviceIterator.hasNext()) {
UsbDevice usbDevice = deviceIterator.next();
Log.i("List", "Model : " +usbDevice.getDeviceName());
Log.i("List", "Id : " +usbDevice.getDeviceId());
}
}
}
Manifest Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pathtech.usbapp" >
<permission android:name="android.hardware.usb.host"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<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_ATTACHED" />
</intent-filter>
</activity>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</application>
</manifest>
manager.getDeviceList() always return zero Can anyone give me any suggestion? Log information gives like below:
09-12 23:26:28.692 5053-5053/com.example.usbapp I/List﹕ size =0
09-12 23:26:28.692 5053-5053/com.example.usbapp I/List﹕ List{ }
Please give me suggestions.. Thanks in advance