Java Code Examples for android.content.pm.PackageManager#FEATURE_USB_ACCESSORY

The following examples show how to use android.content.pm.PackageManager#FEATURE_USB_ACCESSORY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UsbManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of currently attached USB accessories.
 * (in the current implementation there can be at most one)
 *
 * @return list of USB accessories, or null if none are attached.
 */
@RequiresFeature(PackageManager.FEATURE_USB_ACCESSORY)
public UsbAccessory[] getAccessoryList() {
    if (mService == null) {
        return null;
    }
    try {
        UsbAccessory accessory = mService.getCurrentAccessory();
        if (accessory == null) {
            return null;
        } else {
            return new UsbAccessory[] { accessory };
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example 2
Source File: UsbManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the caller has permission to access the accessory.
 * Permission might have been granted temporarily via
 * {@link #requestPermission(UsbAccessory, PendingIntent)} or
 * by the user choosing the caller as the default application for the accessory.
 *
 * @param accessory to check permissions for
 * @return true if caller has permission
 */
@RequiresFeature(PackageManager.FEATURE_USB_ACCESSORY)
public boolean hasPermission(UsbAccessory accessory) {
    if (mService == null) {
        return false;
    }
    try {
        return mService.hasAccessoryPermission(accessory);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example 3
Source File: UsbManager.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Opens a file descriptor for reading and writing data to the USB accessory.
 *
 * <p>If data is read from the {@link java.io.InputStream} created from this file descriptor all
 * data of a USB transfer should be read at once. If only a partial request is read the rest of
 * the transfer is dropped.
 *
 * @param accessory the USB accessory to open
 * @return file descriptor, or null if the accessory could not be opened.
 */
@RequiresFeature(PackageManager.FEATURE_USB_ACCESSORY)
public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
    try {
        return mService.openAccessory(accessory);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example 4
Source File: UsbManager.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Requests temporary permission for the given package to access the accessory.
 * This may result in a system dialog being displayed to the user
 * if permission had not already been granted.
 * Success or failure is returned via the {@link android.app.PendingIntent} pi.
 * If successful, this grants the caller permission to access the accessory only
 * until the device is disconnected.
 *
 * The following extras will be added to pi:
 * <ul>
 * <li> {@link #EXTRA_ACCESSORY} containing the accessory passed into this call
 * <li> {@link #EXTRA_PERMISSION_GRANTED} containing boolean indicating whether
 * permission was granted by the user
 * </ul>
 *
 * @param accessory to request permissions for
 * @param pi PendingIntent for returning result
 */
@RequiresFeature(PackageManager.FEATURE_USB_ACCESSORY)
public void requestPermission(UsbAccessory accessory, PendingIntent pi) {
    try {
        mService.requestAccessoryPermission(accessory, mContext.getPackageName(), pi);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}