这篇文章提到三种方法可以实现所需要的效果:
1,把您的app放到系统应用文件夹下:/system/app/...
2,在AndroidManifest.xml中添加上系统签名;
以上两种方法作为第三方应用的开发者来说都有点难度,第三种方法的实现除了安装apk应用之后第一次插上USB设备弹出对话框:
勾选上 “默认情况下用于该USB设备”,点击确定即可。每次开机后默认打开该app应用。
使用本文提到的第三种方法确实可以避免每次打开app应用都弹出对话框的请求;
3,步骤一:在你的项目中加入包 android.hardware.usb,添加接口文件IUsbManager.java:
package android.hardware.usb;
public interface IUsbManager extends android.os.IInterface
{
/** Local-side IPC implementation stub class. */
public static abstract class Stub extends android.os.Binder implements android.hardware.usb.IUsbManager
{
/** Construct the stub at attach it to the interface. */
public Stub()
{
throw new RuntimeException( "Stub!" );
}
/**
* Cast an IBinder object into an android.hardware.usb.IUsbManager interface,
* generating a proxy if needed.
*/
public static android.hardware.usb.IUsbManager asInterface( android.os.IBinder obj )
{
throw new RuntimeException( "Stub!" );
}
public android.os.IBinder asBinder()
{
throw new RuntimeException( "Stub!" );
}
public boolean onTransact( int code, android.os.Parcel data, android.os.Parcel reply, int f