如何忽略usb host 模式设备连接确认对话框

文章介绍了如何避免在Android设备上使用USB Host模式时出现的设备连接确认对话框。提供了三种解决方案,包括将应用置于系统应用文件夹、添加系统签名到AndroidManifest.xml,以及通过用户设置默认USB应用。重点强调了第三种方法,即用户在首次连接USB设备时选择默认应用,以防止后续每次都弹出权限请求。
摘要由CSDN通过智能技术生成

参考原文地址:http://stackoverflow.com/questions/13726583/bypass-android-usb-host-permision-confirmation-dialog/19681849#19681849

这篇文章提到三种方法可以实现所需要的效果:

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值