USB检测程序显示没有在Android的4.0.3 Pro的微笑,当我连接任何USB [英] USB detection app shows nothing in Android 4.0.3 Smile Pro when i connect any USB
本文介绍了USB检测程序显示没有在Android的4.0.3 Pro的微笑,当我连接任何USB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Eclipse和我已经安装在我的Android手机的应用程序。
I am using Eclipse and I have installed the app in my Android phone.
主要活动code:
包com.example.usbdetection;
package com.example.usbdetection;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
UsbManager usbManager;
PendingIntent mPermissionIntent;
UsbDevice usbDevice;
Intent intent;
final String ACTION_USB_PERMISSION = "com.example.usbdetection.USB_PERMISSION";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(
ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
}
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
@Override
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 ");
}
}
}
}
};
}
清单文件:
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.usbdetection.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>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>
当我运行我的应用程序,并连接它显示没有任何USB。什么错?
When I run my app and connect any USB it shows nothing. whats wrong?.
任何帮助将是AP preciated:)
Any help would be appreciated :)
推荐答案
我已经找到了解决办法:
I have found the solution:
首先,我扎根在我的Android设备。
然后我添加了一个文件名为 android.hardware.usb.host.xml 在等/权限文件夹,其中包括允许
First i rooted my android device. and then i added a file named android.hardware.usb.host.xml in etc/permissions Folder which include permission
<permissions>
<feature name="android.hardware.usb.host" />
</permissions>
而现在它支持主机API。
And now it supports Host API.
这篇关于USB检测程序显示没有在Android的4.0.3 Pro的微笑,当我连接任何USB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文