如何忽略usb host 模式设备连接确认对话框
<li class="alt"><span><span>package android.hardware.usb; </span></span></li><li class=""><span> </span></li><li class="alt"><span>public interface IUsbManager extends android.os.IInterface </span></li><li class=""><span>{ </span></li><li class="alt"><span> /** Local-side IPC implementation stub class. */ </span></li><li class=""><span> public static abstract class Stub extends android.os.Binder implements android.hardware.usb.IUsbManager </span></li><li class="alt"><span> { </span></li><li class=""><span> /** Construct the stub at attach it to the interface. */ </span></li><li class="alt"><span> public Stub() </span></li><li class=""><span> { </span></li><li class="alt"><span> throw new RuntimeException( "Stub!" ); </span></li><li class=""><span> } </span></li><li class="alt"><span> /** </span></li><li class=""><span> * Cast an IBinder object into an android.hardware.usb.IUsbManager interface, </span></li><li class="alt"><span> * generating a proxy if needed. </span></li><li class=""><span> */ </span></li><li class="alt"><span> public static android.hardware.usb.IUsbManager asInterface( android.os.IBinder obj ) </span></li><li class=""><span> { </span></li><li class="alt"><span> throw new RuntimeException( "Stub!" ); </span></li><li class=""><span> } </span></li><li class="alt"><span> </span></li><li class=""><span> public android.os.IBinder asBinder() </span></li><li class="alt"><span> { </span></li><li class=""><span> throw new RuntimeException( "Stub!" ); </span></li><li class="alt"><span> } </span></li><li class=""><span> </span></li><li class="alt"><span> public boolean onTransact( int code, android.os.Parcel data, android.os.Parcel reply, int flags ) throws android.os.RemoteException </span></li><li class=""><span> { </span></li><li class="alt"><span> throw new RuntimeException( "Stub!" ); </span></li><li class=""><span> } </span></li><li class="alt"><span> </span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_getDeviceList</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_openDevice</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_getCurrentAccessory</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_openAccessory</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_setDevicePackage</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_setAccessoryPackage</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_hasDevicePermission</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_hasAccessoryPermission</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_requestDevicePermission</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_requestAccessoryPermission</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_grantDevicePermission</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 10); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_grantAccessoryPermission</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 11); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_hasDefaults</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 12); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_clearDefaults</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 13); </span></span></li><li class=""><span> static final int <span class="attribute">TRANSACTION_setCurrentFunction</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 14); </span></span></li><li class="alt"><span> static final int <span class="attribute">TRANSACTION_setMassStorageBackingFile</span><span> = (android.os.IBinder.FIRST_CALL_TRANSACTION + 15); </span></span></li><li class=""><span> } </span></li><li class="alt"><span> </span></li><li class=""><span> /* Returns a list of all currently attached USB devices */ </span></li><li class="alt"><span> public void getDeviceList( android.os.Bundle devices ) throws android.os.RemoteException; </span></li><li class=""><span> /* Returns a file descriptor for communicating with the USB device. </span></li><li class="alt"><span> * The native fd can be passed to usb_device_new() in libusbhost. </span></li><li class=""><span> */ </span></li><li class="alt"><span> public android.os.ParcelFileDescriptor openDevice( java.lang.String deviceName ) throws android.os.RemoteException; </span></li><li class=""><span> /* Returns the currently attached USB accessory */ </span></li><li class="alt"><span> public android.hardware.usb.UsbAccessory getCurrentAccessory() throws android.os.RemoteException; </span></li><li class=""><span> /* Returns a file descriptor for communicating with the USB accessory. </span></li><li class="alt"><span> * This file descriptor can be used with standard Java file operations. </span></li><li class=""><span> */ </span></li><li class="alt"><span> public android.os.ParcelFileDescriptor openAccessory( android.hardware.usb.UsbAccessory accessory ) throws android.os.RemoteException; </span></li><li class=""><span> /* Sets the default package for a USB device </span></li><li class="alt"><span> * (or clears it if the package name is null) </span></li><li class=""><span> */ </span></li><li class="alt"><span> public void setDevicePackage( android.hardware.usb.UsbDevice device, java.lang.String packageName ) throws android.os.RemoteException; </span></li><li class=""><span> /* Sets the default package for a USB accessory </span></li><li class="alt"><span> * (or clears it if the package name is null) </span></li><li class=""><span> */ </span></li><li class="alt"><span> public void setAccessoryPackage( android.hardware.usb.UsbAccessory accessory, java.lang.String packageName ) throws android.os.RemoteException; </span></li><li class=""><span> /* Returns true if the caller has permission to access the device. */ </span></li><li class="alt"><span> public boolean hasDevicePermission(android.hardware.usb.UsbDevice device) throws android.os.RemoteException; </span></li><li class=""><span> /* Returns true if the caller has permission to access the accessory. */ </span></li><li class="alt"><span> public boolean hasAccessoryPermission( android.hardware.usb.UsbAccessory accessory ) throws android.os.RemoteException; </span></li><li class=""><span> /* Requests permission for the given package to access the device. </span></li><li class="alt"><span> * Will display a system dialog to query the user if permission </span></li><li class=""><span> * had not already been given. </span></li><li class="alt"><span> */ </span></li><li class=""><span> public void requestDevicePermission( android.hardware.usb.UsbDevice device, java.lang.String packageName, android.app.PendingIntent pi ) throws android.os.RemoteException; </span></li><li class="alt"><span> /* Requests permission for the given package to access the accessory. </span></li><li class=""><span> * Will display a system dialog to query the user if permission </span></li><li class="alt"><span> * had not already been given. Result is returned via pi. </span></li><li class=""><span> */ </span></li><li class="alt"><span> public void requestAccessoryPermission( android.hardware.usb.UsbAccessory accessory, java.lang.String packageName, android.app.PendingIntent pi ) throws android.os.RemoteException; </span></li><li class=""><span> /* Grants permission for the given UID to access the device */ </span></li><li class="alt"><span> public void grantDevicePermission( android.hardware.usb.UsbDevice device, int uid ) throws android.os.RemoteException; </span></li><li class=""><span> /* Grants permission for the given UID to access the accessory */ </span></li><li class="alt"><span> public void grantAccessoryPermission( android.hardware.usb.UsbAccessory accessory, int uid ) throws android.os.RemoteException; </span></li><li class=""><span> /* Returns true if the USB manager has default preferences or permissions for the package */ </span></li><li class="alt"><span> public boolean hasDefaults( java.lang.String packageName ) throws android.os.RemoteException; </span></li><li class=""><span> /* Clears default preferences and permissions for the package */ </span></li><li class="alt"><span> public void clearDefaults( java.lang.String packageName ) throws android.os.RemoteException; </span></li><li class=""><span> /* Sets the current USB function. */ </span></li><li class="alt"><span> public void setCurrentFunction( java.lang.String function, boolean makeDefault ) throws android.os.RemoteException; </span></li><li class=""><span> /* Sets the file path for USB mass storage backing file. */ </span></li><li class="alt"><span> public void setMassStorageBackingFile( java.lang.String path ) throws android.os.RemoteException; </span></li><li class=""><span>} </span></li>
这篇文章提到三种方法可以实现所需要的效果:
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 flags ) throws android.os.RemoteException
{
throw new RuntimeException( "Stub!" );
}
static final int TRANSACTION_getDeviceList = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
static final int TRANSACTION_openDevice = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
static final int TRANSACTION_getCurrentAccessory = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
static final int TRANSACTION_openAccessory = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
static final int TRANSACTION_setDevicePackage = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
static final int TRANSACTION_setAccessoryPackage = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
static final int TRANSACTION_hasDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
static final int TRANSACTION_hasAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
static final int TRANSACTION_requestDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8);
static final int TRANSACTION_requestAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9);
static final int TRANSACTION_grantDevicePermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 10);
static final int TRANSACTION_grantAccessoryPermission = (android.os.IBinder.FIRST_CALL_TRANSACTION + 11);
static final int TRANSACTION_hasDefaults = (android.os.IBinder.FIRST_CALL_TRANSACTION + 12);
static final int TRANSACTION_clearDefaults = (android.os.IBinder.FIRST_CALL_TRANSACTION + 13);
static final int TRANSACTION_setCurrentFunction = (android.os.IBinder.FIRST_CALL_TRANSACTION + 14);
static final int TRANSACTION_setMassStorageBackingFile = (android.os.IBinder.FIRST_CALL_TRANSACTION + 15);
}
/* Returns a list of all currently attached USB devices */
public void getDeviceList( android.os.Bundle devices ) throws android.os.RemoteException;
/* Returns a file descriptor for communicating with the USB device.
* The native fd can be passed to usb_device_new() in libusbhost.
*/
public android.os.ParcelFileDescriptor openDevice( java.lang.String deviceName ) throws android.os.RemoteException;
/* Returns the currently attached USB accessory */
public android.hardware.usb.UsbAccessory getCurrentAccessory() throws android.os.RemoteException;
/* Returns a file descriptor for communicating with the USB accessory.
* This file descriptor can be used with standard Java file operations.
*/
public android.os.ParcelFileDescriptor openAccessory( android.hardware.usb.UsbAccessory accessory ) throws android.os.RemoteException;
/* Sets the default package for a USB device
* (or clears it if the package name is null)
*/
public void setDevicePackage( android.hardware.usb.UsbDevice device, java.lang.String packageName ) throws android.os.RemoteException;
/* Sets the default package for a USB accessory
* (or clears it if the package name is null)
*/
public void setAccessoryPackage( android.hardware.usb.UsbAccessory accessory, java.lang.String packageName ) throws android.os.RemoteException;
/* Returns true if the caller has permission to access the device. */
public boolean hasDevicePermission(android.hardware.usb.UsbDevice device) throws android.os.RemoteException;
/* Returns true if the caller has permission to access the accessory. */
public boolean hasAccessoryPermission( android.hardware.usb.UsbAccessory accessory ) throws android.os.RemoteException;
/* Requests permission for the given package to access the device.
* Will display a system dialog to query the user if permission
* had not already been given.
*/
public void requestDevicePermission( android.hardware.usb.UsbDevice device, java.lang.String packageName, android.app.PendingIntent pi ) throws android.os.RemoteException;
/* Requests permission for the given package to access the accessory.
* Will display a system dialog to query the user if permission
* had not already been given. Result is returned via pi.
*/
public void requestAccessoryPermission( android.hardware.usb.UsbAccessory accessory, java.lang.String packageName, android.app.PendingIntent pi ) throws android.os.RemoteException;
/* Grants permission for the given UID to access the device */
public void grantDevicePermission( android.hardware.usb.UsbDevice device, int uid ) throws android.os.RemoteException;
/* Grants permission for the given UID to access the accessory */
public void grantAccessoryPermission( android.hardware.usb.UsbAccessory accessory, int uid ) throws android.os.RemoteException;
/* Returns true if the USB manager has default preferences or permissions for the package */
public boolean hasDefaults( java.lang.String packageName ) throws android.os.RemoteException;
/* Clears default preferences and permissions for the package */
public void clearDefaults( java.lang.String packageName ) throws android.os.RemoteException;
/* Sets the current USB function. */
public void setCurrentFunction( java.lang.String function, boolean makeDefault ) throws android.os.RemoteException;
/* Sets the file path for USB mass storage backing file. */
public void setMassStorageBackingFile( java.lang.String path ) throws android.os.RemoteException;
}
步骤二:再创建android.os包,添加ServiceManager.java类:
package android.os;
import java.util.Map;
public final class ServiceManager
{
public static IBinder getService( String name )
{
throw new RuntimeException( "Stub!" );
}
/**
* Place a new @a service called @a name into the service
* manager.
*
* @param name the name of the new service
* @param service the service object
*/
public static void addService( String name, IBinder service )
{
throw new RuntimeException( "Stub!" );
}
/**
* Retrieve an existing service called @a name from the
* service manager. Non-blocking.
*/
public static IBinder checkService( String name )
{
throw new RuntimeException( "Stub!" );
}
public static String[] listServices() throws RemoteException
{
throw new RuntimeException( "Stub!" );
}
/**
* This is only intended to be called when the process is first being brought
* up and bound by the activity manager. There is only one thread in the process
* at that time, so no locking is done.
*
* @param cache the cache of service references
* @hide
*/
public static void initServiceCache( Map<String, IBinder> cache )
{
throw new RuntimeException( "Stub!" );
}
}
如何忽略usb host 模式设备连接确认对话框的更多相关文章
- android usb Host模式下与usb Hid 设备的通信
做android 与USB HID设备的通信有段时间了,总结一下遇到的问题和解决方法: 1,第一次遇到的问题:android 版本低不支持usb hid, 被要求做相关项目的时候,就从mUsbMana ...
- USB协议-检测设备连接与速度
在USB设备连接时,USB系统能自动检测到这个连接,并识别出其采用的数据传输速率.USB采用在D+或D-线上增加上拉电阻的方法来识别低速和全速设备. USB支持3种类型的传输速率:1.5Mb/s的低速 ...
- Android开启OTG功能/USB Host API功能
Android USB 模式简介 设备模式 当计算机或其他USB主机需要连接安卓设备时,此时安卓设备是作为"USB设备"角色的,在计算机上显示为 USB 外设.现在的安卓设备已经被 ...
- 翻译Android USB HOST API
翻译Android USB HOST API 源代码地址:http://developer.android.com/guide/topics/connectivity/usb/host.html 译者 ...
- [Linux网络、命名空间、veth设备对、docker的host模式、container模式、none模式、brideg模式、网桥的增删查,容器与网桥的连接断开]
[Linux网络.命名空间.veth设备对.docker的host模式.container模式.none模式.brideg模式.网桥的增删查,容器与网桥的连接断开] 网络名称空间 为了支持网络协议栈的 ...
- 豌豆荚不能连接三星S4手机,提示打开手机的“USB调试模式”,但却找不到在哪儿可以设置
1. 问题 豌豆荚不能连接三星S4手机,下载了三星S4手机的驱动后,提示打开手机的“USB调试模式”,但却找不到在哪儿可以设置. 2. 原因 S4 默认隐藏开发者选项,所以默认不可以设置“USB调试模 ...
- Android USB Host 与 Hid 设备通信bulkTransfer()返回-1问题的原因
近期一直在做Android USB Host 与USB Hid设备(STM32FXXX)的通信,遇到了很多问题.项目源码以及所遇到的其他问题可以见本博客其他相关文章,这里重点讲一下bulkTransf ...
- android usb host 读写USB设备
自android3.1以后android增加了操作USB设备的API. 官网地址:http://developer.android.com/guide/topics/connectivity/usb/ ...
- 【转】Android实战技巧之四十九:Usb通信之USB Host
零 USB背景知识 USB是一种数据通信方式,也是一种数据总线,而且是最复杂的总线之一. 硬件上,它是用插头连接.一边是公头(plug),一边是母头(receptacle).例如,PC上的插座就是母头 ...
随机推荐
- Apache Rewrite url重定向功能的简单配置
http://www.jb51.net/article/24435.htm 1.Apache Rewrite的主要功能 就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范.平时帮助我 ...
- QT/C++ 智能指针
什么是智能指针? 为什么用智能指针? 还有哪些关于内存管理方面的知识点,需要注意的?
- 客户调用COM流程
参考:COM技术内幕 DllGetClassObjecthttps://msdn.microsoft.com/en-us/library/windows/desktop/ms680760.aspx ...
- 计算序列中第k小的数
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4046399.html 使用分治算法,首先选择随机选择轴值pivot,并使的序列中比pivot ...
- Git-it:一个学习Git和Github的教程(软件)
Git-it https://github.com/jlord/git-it 2016-08-01 在FreeCodeCamp的引导下了解到的Git-it.OSC有收录. Git-it是一个指导使用G ...
- MSChart实例
MSChart是VS中自带的图表控件,功能比较强大,效果也比较丰富.下面只提供一个例子,以供新接触的朋友参考. 先看下效果图: 看完效果图上代码啦. 使用这个控件需要先在页面注册一下. <%@ ...
- C# DllImport的用法
大家在实际工作学习C#的时候,可能会问:为什么我们要为一些已经存在的功能(比如Windows中的一些功能,C++中已经编写好的一些方法)要重新编写代码,C#有没有方法可以直接都用这些原本已经存在的功能 ...
- logback使用笔记
三大主要元素 looger:记录日志 appender:输出目的地 layout:输出格式 必要步骤: 一.引入包: import org.slf4j.Logger; import org.slf4j ...
- CentOS 6.X更新Python2.7.x版本 安装pip
在安装新版之前安装 先安装bz2.zlib,执行下列代码进行安装 yum install -y zlib-devel bzip2-devel xz-libs wget openssl openssl- ...
- Python+Bottle+Sina SAE快速构建网站
Bottle是新生一代Python框架的代表,利用Bottle构建网站将十分简单. Sina SAE是国内较出名的云平台之一,十分适用于个人网站的开发或创业公司网站开发. 下面将介绍如果通过Pytho ...