35

業界でAndroidを使いたい、

slickdevlabs.comライブラリを使用してProfilicおよびFtdiUSBtoSerialチップに問題なく接続できます。

アプリケーションにはサービスがあり、起動時に起動し、USBシリアルポートに接続して他のことを行います。

私の問題は、ホストデバイスがユーザーと対話しないことです。

だからアンドロイドが尋ねるとき

Allow the app "MyAPP" to access the USB device ?
[checkmark]Use by default for this USB device
Cancel            OK

[OK]をクリックする人は誰もいません。

[デフォルトで使用する...]チェックボックスをオンにしても、USBを再挿入するか、ホストデバイスを再起動すると、次回の起動時に再度要求されます。

スーパーユーザーモードでサービスとアプリを実行しましたが、違いはありません。もう一度尋ねます。

インテントフィルターを追加しましたが、違いはありません。毎回尋ねられます。

        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
        </intent-filter>

        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter" />
        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
            android:resource="@xml/device_filter" />

それをバイパスまたは無効にする方法についての意見はありますか?

ルートとSUにアクセスできます。

4

13 に答える 13

28

少し遅いのは知っていますが、それでも...

同じような問題があり、なんとか解決できたと思います。Androidが内部で使用するサービスがあり、USBデバイスとアクセサリを管理できます。このサービスはサードパーティの開発者からは隠されており、文書化されていません。UsbPermissionActivityのソースコードを確認すると、そのサービスがどのように呼び出されているかを理解できます。サービスを呼び出すために、IUsbManagerインターフェイスとServiceManagerクラスが使用されます。これらも両方とも非表示になっているため、直接使用することはできません。しかし、あなたができることは、まったく同じ名前で、対応する名前空間(パッケージ)にスタブを作成することです。そうすれば、ランタイム環境で実際のものを使用しながら、そのコードをコンパイルできるようになります。

唯一の要件、アプリケーションがシステムのものである必要があることです。つまり、アプリケーションは/ system /app/ディレクトリに配置されている必要があります。お使いのデバイスはルート化されているので、それは問題ではないはずです。

したがって、プロジェクトにパッケージ「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!" );
    }
}

これらのクラスのインターフェースは、Androidのバージョンによって異なる場合があることに注意してください。私の場合、バージョンは4.0.3です。したがって、別のバージョンのAndroidを使用していて、このコードが機能しない場合は、特定のバージョンのOSのソースコードを確認する必要があります。

このサービスを使用してすべてのFTDIデバイスにアクセス許可を付与する例を次に示します。

import java.util.HashMap;
import java.util.Iterator;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.IBinder;
import android.os.ServiceManager;

public class LaunchReceiver extends BroadcastReceiver
{
    public void onReceive( Context context, Intent intent )
    {
        String action = intent.getAction();
        if( action != null && action.equals( Intent.ACTION_BOOT_COMPLETED ) )
        {
            try
            {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo ai = pm.getApplicationInfo( YOUR_APP_PACKAGE_NAMESPACE, 0 );
                if( ai != null )
                {
                    UsbManager manager = (UsbManager) context.getSystemService( Context.USB_SERVICE );
                    IBinder b = ServiceManager.getService( Context.USB_SERVICE );
                    IUsbManager service = IUsbManager.Stub.asInterface( b );

                    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
                    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
                    while( deviceIterator.hasNext() )
                    {
                            UsbDevice device = deviceIterator.next();
                            if( device.getVendorId() == 0x0403 )
                            {
                                service.grantDevicePermission( device, ai.uid );
                                service.setDevicePackage( device, YOUR_APP_PACKAGE_NAMESPACE );
                            }
                    }
                }
            }
            catch( Exception e )
            {
                trace( e.toString() );
            }
        }
    }
}

もう1つ、マニフェストに次の権限を追加する必要があります(Lintは気に入らないかもしれませんが、プロジェクトのプロパティで重大度レベルをいつでも変更できます)。

<uses-permission android:name="android.permission.MANAGE_USB" />
于 2013-03-13T06:00:43.487 に答える
13

@d_d_t aswerは素晴らしいですが、Android>4.2.2では機能しません。このインターフェースを使用します:

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 {
    private static final java.lang.String DESCRIPTOR = "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!" );
    }

    @Override
    public android.os.IBinder asBinder() {
        throw new RuntimeException( "Stub!" );
    }

    @Override
    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);
    static final int TRANSACTION_allowUsbDebugging = (android.os.IBinder.FIRST_CALL_TRANSACTION + 16);
    static final int TRANSACTION_denyUsbDebugging = (android.os.IBinder.FIRST_CALL_TRANSACTION + 17);
}

/* 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, int userId)
        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, int userId)
        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, int userId)
        throws android.os.RemoteException;

/* Clears default preferences and permissions for the package */
public void clearDefaults(java.lang.String packageName, int userId)
        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;

/*
 * Allow USB debugging from the attached host. If alwaysAllow is true, add
 * the the public key to list of host keys that the user has approved.
 */
public void allowUsbDebugging(boolean alwaysAllow,
        java.lang.String publicKey) throws android.os.RemoteException;

/* Deny USB debugging from the attached host */
public void denyUsbDebugging() throws android.os.RemoteException;
}

そして、ユーザーIDを追加するコードを変更します。

...
service.setDevicePackage( usbDevice, YOUR_APP_PACKAGE_NAMESPACE, ai.uid ); 
....
于 2013-10-30T12:09:13.663 に答える
9

私はポップアップウィンドウで同じ問題を抱えていて、誰もそれをクリックしませんでした。しかし、私は別の解決策を見つけました(root化されたデバイス用)。ポップアップは、AndroidによってクラスUsbPermissionActivityで生成されます(UsbPermissionActivityはUsbSettingsManagerによって開始されます)。Androidのソースコードを見て、何が起こっているかを確認してください。ここでの良い点は、UsbPermissionActivityのバイトコードを操作してすべてのUsbDevicesを受け入れることができることです。そのためには、ツールSmali/Baksmaliが必要です。https://code.google.com/p/smali/

  1. デバイスでファイルSystemUI.apkを見つけます
  2. を使用してコンピュータにコピーしますadb pull path/to/SystemUI.apk
  3. APKを解凍します
  4. でclasses.dexファイルを分解しますjava -jar baksmali.jar classes.dex
  5. UsbPermissionActivityファイルを見つけ、その中の次の行を見つけます

    invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->setupAlert()V

  6. コメントアウトして2行追加して変更します

#invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->setupAlert()V const/4 v0, 0x1 iput-boolean v0, p0, Lcom/android/systemui/usb/UsbPermissionActivity;->mPermissionGranted:Z invoke-virtual {p0}, Lcom/android/systemui/usb/UsbPermissionActivity;->finish()V

  1. で組み立てるjava -jar smali.jar -o classes.dex out
  2. 元のclasses.dexを置き換え、すべてをもう一度SystemUI.apkに圧縮します
  3. デバイス上の元のSystemUI.apkadb push services.jar path/to/SystemUI.apkを、ファイルマネージャーapで動作しない場合は置き換えます。
于 2015-05-31T22:10:11.950 に答える
5

あなたがアンドロイドシステムをコンパイルするオプションを持っているなら、あなたがすることができないことは何もありません。

あなたは付け加えられます

public void onStart() {
    super.onStart();
    mPermissionGranted = true;

    finish();
}

フレームワーク/base/packages/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.javaへ

権限確認ポップアップをバイパスします。

于 2014-11-17T08:09:08.553 に答える
5

解決策は、インテントフィルタを使用android:directBootAware="true"し、関連付けられたアクティビティに属性を追加してUSB_DEVICE_ATTACHED、起動/再起動後にイベントが正しく受信されるようにすることです。USB次のようなインテントフィルターのみを使用して、コードでデバイスのアクセス許可を要求しないことが重要です。

<manifest>
    <uses-feature android:name="android.hardware.usb.host" />
    <activity
        ...
        android:directBootAware="true">

        <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>
</manifest>

次のようなdevice_filter XMLリソースファイルを使用します。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <usb-device vendor-id="1234" product-id="5678" />
</resources>
于 2020-03-19T22:31:54.093 に答える
4

Androidは、この種の使用法をそのままサポートするようには設計されていません。個人的には、非対話型の使用法として、LinuxカーネルでUSBシリアルドライバーを使用し、AndroidUSBAPIをスキップすることを検討したくなるでしょう。ただし、Androidのインストールを大幅に変更する必要があります-カーネル構成を変更したり、モジュールをロードしたり、デバイスファイルを作成してアクセス許可や所有者を設定したり、許可されたアプリにUNIXグループとAndroidのアクセス許可を追加したりできます。アクセスします。

または、Androidソースを調べて、ユーザー確認を無効にすることもできます。ただし、デバイスのソースからのAndroidビルドがない場合、ベンダーのデバイスで実行するようにオープンソースのAndroidを適応させることは簡単ではない可能性があるため、これはLinuxレベルのアイデアよりも難しい場合があります(誰かがすでに-問題のデバイスに対して十分に機能するソースビルド)

つまり、root / suアクセスはアプリケーション自体には適用されません。つまり、rootハックが残したツールを実行する方法を知っているアプリケーションは、rootとして実行されるヘルパープログラムを起動できますが、アプリケーション自体はそうではありません。できません。rootを使用してアプリをシステムパーティションにインストールすると、非定型のAndroid権限が取得される可能性がありますが、USBで役立つものがあるかどうかを確認する必要があります。

于 2012-12-05T15:56:26.183 に答える
3

使用しているアクセサリを事前にホワイトリストに登録することが最善の解決策になると思います。これを行うには、この場所にファイルusb_device_manager.xmlを追加する必要があります/ data / system / users / 0
// 0はユーザーIDであることに注意してください。Androidでユーザーを追加しなかった場合は、おそらく0になります。それに応じてこのIDを変更しました

ファイルは次のようになります。

<settings>
<preference package="<PACKAGE NAME OF APP YOU WANT TO START ON CONNECTIONCTION>">
    <usb-accessory manufacturer="<NAME OF MANUFECTURER LIKE ONE REGISTERED IN meta-data in the manifest>" model="<MODEL NAME LIKE ONE REGISTERED IN meta-data in the manifest>" version="<VERSION LIKE ONE REGISTERED IN meta-data in the manifest>" />
</preference>

このhttp://www.embeddedartists.com/products/app/aoa_kit.phpのようなボードの場合、次のようになります。

 <?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<settings>
<preference package="com.embeddedartists.aoa">
    <usb-accessory manufacturer="Embedded Artists AB" model="AOA Board - Basic" version="1.0" />
</preference>

于 2015-07-30T10:11:21.657 に答える
2

Androidデベロッパーのドキュメントによると、アプリがマニフェストインテントフィルターを介して開始されたときに、接続されたUSBデバイスへのアクセス許可が既にあります。おそらく、このアプローチを試して、使用するデバイスに完全に一致するフィルターを作成して、他のアプリもデバイスと通信することを防ぐ必要があります。

http://developer.android.com/guide/topics/connectivity/usb/host.html#permission-dの「注」を参照してください

于 2013-03-05T08:43:24.337 に答える
1

これを実現する1つの方法は、実際には確認が削除されないことに注意してください。の場所を特定しcheckbox、Androidに相当するRobotクラスを使用して選択し、を選択することOKです。バックグラウンドで実行されるアプリケーションを作成することもできます。特にこの目的のために、前述のスタートアップサービスから呼び出すこともできます。

于 2013-01-20T22:45:51.857 に答える
0

Androidのソースコードにアクセスできる場合は、権限ダイアログを無効にするために必要なコードは次のとおりです

https://gitlab.tubit.tu-berlin.de/justus.beyer/streamagame_platform_frameworks_base/commit/e97b62ed0d4050acacbf54781435686ea28edd73

上記のコード更新により、使用できる構成オプションが作成されます。または、代わりにmDisablePermissionDialogs、権限ダイアログを無効にする代わりに値trueを使用してハードコードすることができます。

services/usb/java/com/android/server/usb/UsbSettingsManager.java

于 2019-04-11T04:53:02.790 に答える
-1

最初に確認が必要な場合は、[常に]を選択できます。その後、Androidデバイスの電源を切り、電源を入れても、アプリにはUSB2Serialへのアクセス許可があります。言うまでもなく、一度だけ確認してください!

于 2017-01-25T10:52:19.177 に答える
-1

同じ問題が発生しました。USBケーブルを接続するたびに権限ポップアップが表示されます。これを解決するには、マニフェストにフィルターを追加し、VIDとPIDのxmlファイルを追加しました。USBデバイスのフィルタリングが次のように設定されていることを確認してください。上記またはここに記載されているSOリンクを使用すると、適切なVIDとPIDを配置できます。それは私の問題でした、私は私のデバイスに一致するVIDとPIDを入れませんでした

于 2018-01-30T18:48:56.393 に答える
-2

でいくつかの変更を加えることでこれを行うことができると思います/etc/udev。ベンダーIDとデバイスIDを51-android.rulesファイルに追加できます。

于 2013-01-15T08:19:57.840 に答える