pomiń okno dialogowe potwierdzenia uprawnień hosta USB w systemie Android

Chcę używać Androida w przemyśle.]} [[2]}Mogę podłączyć do Profilic i FTDI USB do szeregowych układów z slickdevlabs.com biblioteka bez problemu.

Aplikacja ma usługę i uruchamia się po rozruchu, podłączyć do portu szeregowego usb i zrobić inne rzeczy.

Mój problem polega na tym, że urządzenie hosta nie ma żadnej interakcji z użytkownikiem,

Więc kiedy android pyta

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

Nie ma osoby do kliknięcia ok.

Nawet gdy sprawdzam użycie przez default... pole wyboru, jeśli ponownie włożę USB lub zrestartuję urządzenie hosta, zapyta ponownie przy następnym rozruchu.

Uruchomiłem usługę i aplikację w trybie SuperUser, ale bez różnicy, pyta ponownie.

Dodałem filtr intencyjny, ale bez różnicy, pyta mnie za każdym razem.

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

Jakieś opinie jak to ominąć lub wyłączyć ?

Mam dostęp root i SU.
Author: zx81, 2012-12-05

12 answers

Wiem, że jest trochę późno, ale i tak...

Miałem ten sam problem i myślę, że udało mi się go rozwiązać. Istnieje usługa, której Android używa wewnętrznie, która pozwala zarządzać urządzeniami USB i akcesoriami. Ta usługa jest ukryta przed twórcami thrid party i nie jest udokumentowana. Jeśli sprawdzisz kod źródłowy UsbPermissionActivity, będziesz w stanie dowiedzieć się, jak ta usługa jest wywoływana. Do wywołania usługi wykorzystywane są Interfejs IUsbManager oraz Klasa ServiceManager. Oba są również ukryte, więc nie można ich używać bezpośrednio. Ale to, co możesz zrobić, to twórz ich stuby o dokładnie tych samych nazwach i w odpowiednich przestrzeniach nazw (pakietach). Wtedy będziesz mógł skompilować ten kod, podczas gdy środowisko uruchomieniowe będzie używać rzeczywistych rzeczy.

Jedynym wymogiem jest to, że Twoja aplikacja musi być systemowa - czyli musi znajdować się w katalogu /system/app/. Ponieważ urządzenie jest zakorzenione, że nie powinno być problem.

Więc będziesz musiał dodać pakiet do swojego projektu: " android.sprzęt.usb "i umieścić w nim plik o nazwie" IUsbManager.java " o następującej treści:

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;
}

Następnie inny pakiet: " android.os "with" 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!" );
    }
}

Zauważ, że interfejsy tych klas mogą się zmieniać w zależności od wersji Androida. W moim przypadku wersja jest 4.0.3. Więc jeśli masz inną wersję Androida i ten kod nie działa będziesz musiał sprawdzić kod źródłowy dla konkretnej wersji systemu operacyjnego.

Oto przykład użycia usługi do nadawania uprawnień wszystkim urządzeniom 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() );
            }
        }
    }
}

Jeszcze jedno-będziesz musiał dodać następujące uprawnienia do manifestu (Lintowi może się to nie podobać, ale zawsze możesz zmienić poziom ważności we właściwościach projektu):

<uses-permission android:name="android.permission.MANAGE_USB" />
 23
Author: d_d_t,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-13 15:57:20

@d_d_t aswer jest świetny, ale nie działa na nowym 4.2.2. Użyj tego interfejsu:

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;
}

I zmodyfikować kod dodając ID użytkownika:

...
service.setDevicePackage( usbDevice, YOUR_APP_PACKAGE_NAMESPACE, ai.uid ); 
....
 9
Author: Alvins,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-30 12:09:13

Jeśli masz możliwość skompilowania systemu android, to nie ma nic, czego nie możesz zrobić.

Możesz dodać

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

    finish();
}

Do frameworków / base/packages/SystemUI/src/com/android/systemui/usb / Usbpermission.java

Aby ominąć wyskakujące okienko potwierdzenia uprawnień.

 5
Author: Lewisou,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-17 08:09:08

Miałem ten sam problem z wyskakującym oknem i nikt na nie nie klikał. Ale znalazłem inne rozwiązanie (dla urządzeń zakorzenionych). Wyskakujące okienko jest generowane przez Androida w klasie UsbPermissionActivity (a usbpermissionactivity jest uruchamiane przez UsbSettingsManager). Spójrz na kod źródłowy Androida, aby zobaczyć, co się dzieje. Dobrą rzeczą jest to, że możemy manipulować kodem bajtowym UsbPermissionActivity, aby zaakceptować wszystkie urządzenia UsbDevices. Potrzebujesz narzędzia Smali / Baksmali aby zrób to. https://code.google.com/p/smali/

  1. zlokalizuj plik SystemUI.apk na urządzeniu
  2. skopiuj go do komputera za pomocą adb pull path/to/SystemUI.apk
  3. Rozpakuj apk
  4. demontować klasy.plik dex z java -jar baksmali.jar classes.dex
  5. Znajdź plik UsbPermissionActivity, a wewnątrz niego znajdź linię, która mówi

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

  6. Zmień to komentując i dodając dwa nowe linie

#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. zmontuj go za pomocą java -jar smali.jar -o classes.dex out
  2. Zastąp oryginalne klasy.dex i zip wszystko ponownie do SystemUI.apk
  3. Zastąp oryginalny system.apk na urządzeniu z adb push services.jar path/to/SystemUI.apk lub jeśli to nie działa z ap filemanager
 5
Author: user2574572,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-10 12:20:32

Android naprawdę nie jest zaprojektowany do obsługi tego rodzaju użytkowania po wyjęciu z pudełka. Osobiście, dla nieinteraktywnego użytkowania, chciałbym pokusić się o rozważenie użycia sterownika szeregowego USB w jądrze Linuksa i pominięcie API USB Androida. Ale musisz być w stanie poważnie zmodyfikować instalację Androida-zmienić konfigurację jądra i / lub załadować moduł, utworzyć pliki urządzeń i ustawić ich uprawnienia lub właścicieli, ewentualnie dodać grupę unix i uprawnienia Androida dla aplikacji dozwolonych do uzyskaj dostęp.

LUB możesz przejrzeć źródło Androida i wyłączyć potwierdzenie użytkownika; ale jeśli nie masz kompilacji ze źródła dla urządzenia, może to być trudniejsze niż pomysł na poziomie Linuksa, ponieważ dostosowanie open source android do działania na urządzeniu dostawcy może być nietrywialne (chyba że ktoś oferuje już kompilację ze źródła, która jest wystarczająco funkcjonalna dla danego urządzenia)

Orientacyjnie, dostęp root/su Nie dotyczy samych aplikacji - tylko oznacza to, że aplikacja, która wie, jak uruchomić cokolwiek narzędzie Twój root hack pozostawione, można uruchomić program pomocniczy, który działa jako root, ale sama aplikacja nie i nie może. Korzystanie z roota do zainstalowania aplikacji na partycji systemowej może uzyskać nietypowe uprawnienia Androida, ale musisz sprawdzić, czy są takie, które pomogą Ci z usb.

 4
Author: Chris Stratton,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-05 15:56:26

Zgodnie z dokumentacją deweloperów Androida masz już uprawnienia do dołączonego urządzenia USB, gdy aplikacja zostanie uruchomiona przez filtr manifest intent. Być może powinieneś spróbować tego podejścia i napisać filtr dokładnie pasujący do urządzenia, którego chcesz użyć, aby zapobiec temu, że inne aplikacje również chcą komunikować się z urządzeniem.

Zobacz "notkę" na http://developer.android.com/guide/topics/connectivity/usb/host.html#permission-d

 3
Author: PieterAelse,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-05 08:43:24

Jednym ze sposobów, aby to osiągnąć, zauważ, że nie pozbawia to potwierdzenia, byłoby wskazanie lokalizacji checkbox i użycie odpowiednika Androida Robot Klasa, aby ją wybrać, a następnie wybrać OK. Możesz napisać aplikację, która działa w tle, może być nawet wywołana przez tę usługę startową, o której wspomniałeś, specjalnie w tym celu.

 2
Author: cnexus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-20 22:45:51

Myślę, że biała lista akcesoriów, których używasz z góry, będzie najlepszym rozwiązaniem. Aby to zrobić, musisz dodać plik usb_device_manager.xml w tym miejscu / data / system / users / 0
// Zauważ, że 0 to identyfikator użytkownika, prawdopodobnie będzie to 0, jeśli nie dodałeś więcej użytkowników w Androidzie, ale jeśli odpowiednio zmieniłeś ten identyfikator

Tak powinien wyglądać plik:

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

Na taką tablicę http://www.embeddedartists.com/products/app/aoa_kit.php it jest:

 <?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>

 2
Author: PSIXO,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-30 10:11:21

Myślę, że możemy to zrobić, dokonując pewnych modyfikacji w /etc/udev. Możemy dodać identyfikator dostawcy i identyfikator urządzenia do pliku 51-android.rules.

 0
Author: user1979609,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-20 22:45:31

Po raz pierwszy, gdy wymaga potwierdzenia, możesz wybrać "zawsze", a następnie nawet jeśli urządzenie z Androidem jest wyłączone i włączone, Twoja aplikacja nadal ma uprawnienia dostępu do USB2Serial. Tylko jeden raz potwierdź!

 0
Author: cantonics,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-08 04:55:27

Miałem ten sam problem, uprawnienia popup pojawiają się za każdym razem podłączyć kabel USB, aby go rozwiązać po prostu dodał filtr w manifeście i pliku xml dla VID i PID, po prostu upewnij się, że masz skonfigurować filtrowanie urządzenia USB jak sugerowane w tak link powyżej lub jak udokumentowane tutaj, i umieścić dobre VID i PID. To był mój problem, nie umieściłem VID i PID, które pasują do mojego urządzenia

 0
Author: lotfi Raghib,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-30 18:48:56

Jeśli chcesz skopiować/zapisać na pendrive możesz użyć

Following method with Linx commands doCommand("mkdir /mnt/usbhost1/dirname")

private boolean doCommand(String[] commands)
{

    boolean ran = false;
    try
    {

        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        for (String single : commands) {
            os.writeBytes(single + "\n");
            os.flush();
        }
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();
        ran = true;
    }
    catch(Exception ex)
    {

    }
    return ran;
}

Mam następujące uprawnienia w manifeście, aby niestety nie pamiętać, które z nich są koniecznością.

<permission android:name="com.android.example.USB_PERMISSION"/>
<permission android:name= "android.permission.INSTALL_PACKAGES"/>
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<data android:scheme="file" />

Jeśli chcesz zrobić cokolwiek innego, może to nie być dla Ciebie zbyt przydatne, przykro Mi

 -1
Author: SatanEnglish,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-19 04:40:24