当前位置: 首页>>代码示例>>Java>>正文


Java UsbAccessory类代码示例

本文整理汇总了Java中android.hardware.usb.UsbAccessory的典型用法代码示例。如果您正苦于以下问题:Java UsbAccessory类的具体用法?Java UsbAccessory怎么用?Java UsbAccessory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UsbAccessory类属于android.hardware.usb包,在下文中一共展示了UsbAccessory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public void setup(Context context) {

        mManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
        UsbAccessory[] accessoryList = mManager.getAccessoryList();
        PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0,
                new Intent(ACTION_USB_PERMISSION), 0);
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        context.registerReceiver(mUsbReceiver, filter);
        mManager.requestPermission(accessoryList[0], mPermissionIntent);


        if (accessoryList[0] != null) {

            mAccessory = accessoryList[0];
            if (mManager.hasPermission(mAccessory)) {
                openAccessory(mAccessory);
            }
        }

    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:21,代码来源:AdkPort.java

示例2: checkForDJIAccessory

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public void checkForDJIAccessory() {
    mUsbManager = (UsbManager) BridgeApplication.getInstance().getSystemService(Context.USB_SERVICE);
    UsbAccessory[] accessoryList = mUsbManager.getAccessoryList();
    if (accessoryList != null
        && accessoryList.length > 0
        && !TextUtils.isEmpty(accessoryList[0].getManufacturer())
        && accessoryList[0].getManufacturer().equals("DJI")) {
        BridgeApplication.getInstance().getBus().post(new RCConnectionEvent(true));
        //Check permission
        mAccessory = accessoryList[0];
        if (mUsbManager.hasPermission(mAccessory)) {
            Log.d(TAG, "RC CONNECTED");
        } else {
            Log.d(TAG, "NO Permission to USB Accessory");
            DJIRemoteLogger.e(TAG, "NO Permission to USB Accessory");
            //mUsbManager.requestPermission(mAccessory, null);
        }
    } else {
        BridgeApplication.getInstance().getBus().post(new RCConnectionEvent(false));
        Log.d(TAG, "RC DISCONNECTED");
    }
}
 
开发者ID:dji-sdk,项目名称:Android-Bridge-App,代码行数:23,代码来源:USBConnectionManager.java

示例3: call

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public FREObject call(FREContext ctx, FREObject[] args){
    UsbContext usbCtx = (UsbContext) ctx;
    ArrayList<UsbAccessory> accessories = usbCtx.usbAccessories();
    Iterator<UsbAccessory> accessoryIterator = accessories.iterator();
    JSONArray jsonArray = new JSONArray();
    while (accessoryIterator.hasNext()) {
        UsbAccessory accessory = accessoryIterator.next();
        JSONObject jsonObject = new JSONObject();
        UsbEvent.addUsbToJson(accessory, jsonObject);
        jsonArray.put(jsonObject);
    }
    try{
        return FREObject.newObject(jsonArray.toString());
    }catch(FREWrongThreadException e){
    }
    return null;
}
 
开发者ID:GIGATeam,项目名称:UsbExtension,代码行数:18,代码来源:GetAccessoriesFunction.java

示例4: onResume

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
@Override
public void onResume() {
    super.onResume();

    if( mOutputStream != null ) {
        return;
    }

    UsbAccessory[] accessories = mUsbManager.getAccessoryList();
    UsbAccessory accessory = ( accessories == null ? null : accessories[0] );
    if( accessory != null ) {
        if( mUsbManager.hasPermission( accessory ) ) {
            openAccessory( accessory );
        } else {
            synchronized( mUsbReceiver ) {
                if( !mPermissionRequestPending ) {
                    mUsbManager.requestPermission( accessory, mPermissionIntent );
                    mPermissionRequestPending = true;
                }
            }
        }
    }
}
 
开发者ID:Lakkichand,项目名称:AndroidDemoProjects,代码行数:24,代码来源:LEDControlFragment.java

示例5: attachUsbReceiver

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
private void attachUsbReceiver() {
    // Broadcast Receiver
    mUsbReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (action.equals(UsbManager.ACTION_USB_ACCESSORY_DETACHED)) {
                UsbAccessory usbAccessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
                if (usbAccessory != null && usbAccessory.equals(mUsbAccessory)) {
                    closeAccessory();
                }
            }
        }
    };
}
 
开发者ID:palazzem,项目名称:adk-toolkit,代码行数:17,代码来源:AdkManager.java

示例6: detectAccessory

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
private void detectAccessory() {
    while (!mIsAttached) {
        if (mIsShutdown) {
            mHandler.sendEmptyMessage(STOP_THREAD);
            return;
        }
        try {
            Thread.sleep(CONNECT_COOLDOWN_MS);
        } catch (InterruptedException exception) {
            // pass
        }
        final UsbAccessory[] accessoryList = mUsbManager.getAccessoryList();
        if (accessoryList == null || accessoryList.length == 0) {
            continue;
        }
        if (accessoryList.length > 1) {
            Log.w(TAG, "Multiple accessories attached!? Using first one...");
        }
        maybeAttachAccessory(accessoryList[0]);
    }
}
 
开发者ID:chris-blay,项目名称:android-open-accessory-bridge,代码行数:22,代码来源:AndroidOpenAccessoryBridge.java

示例7: USBControl

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public USBControl(Context main, Handler ui) {
	super("USBControlSender");
	UIHandler = ui;
	context = main;

	mManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
	UsbAccessory[] accessoryList = mManager.getAccessoryList();
	PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context,
			0, new Intent(ACTION_USB_PERMISSION), 0);
	IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
	context.registerReceiver(mUsbReceiver, filter);

	UsbAccessory mAccessory = (accessoryList == null ? null
			: accessoryList[0]);
	if (mAccessory != null) {

		while (!mManager.hasPermission(mAccessory)) {
			mManager.requestPermission(mAccessory, mPermissionIntent);
		}
		openAccessory(mAccessory);

	}

}
 
开发者ID:praveendath92,项目名称:bard-droid,代码行数:25,代码来源:USBControl.java

示例8: connectToAccessory

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
/**
 * Attempts to connect to the specified accessory.
 *
 * If the permission is already granted, opens the accessory. Otherwise,
 * requests permission to use it.
 *
 * @param accessory Accessory to connect to
 */
private void connectToAccessory(UsbAccessory accessory) {
    final State state = getState();
    switch (state) {
        case LISTENING:
            UsbManager usbManager = getUsbManager();
            if (usbManager.hasPermission(accessory)) {
                logI("Already have permission to use " + accessory);
                openAccessory(accessory);
            } else {
                logI("Requesting permission to use " + accessory);

                PendingIntent permissionIntent = PendingIntent
                        .getBroadcast(getContext(), 0,
                                new Intent(ACTION_USB_PERMISSION), 0);
                usbManager.requestPermission(accessory, permissionIntent);
            }

            break;

        default:
            logW("connectToAccessory() called from state " + state +
                    "; doing nothing");
    }
}
 
开发者ID:smartdevicelink,项目名称:sdl_android,代码行数:33,代码来源:USBTransport.java

示例9: getList

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public String[] getList(Context context) {

        mManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);

        UsbAccessory[] accessoryList = mManager.getAccessoryList();
        String[] accessoryLists = new String[1];
        for (int i = 0; i < accessoryLists.length; i++) {
            accessoryLists[i] = accessoryList[i].getModel()
                    + " v" + accessoryList[i].getVersion()
                    + " by " + accessoryList[i].getManufacturer();


        }
        return accessoryLists;
    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:16,代码来源:AdkPort.java

示例10: openAccessory

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
private void openAccessory(UsbAccessory accessory) {
    mAccessory = accessory;
    mFileDescriptor = mManager.openAccessory(accessory);
    if (mFileDescriptor != null) {
        FileDescriptor fd = mFileDescriptor.getFileDescriptor();
        mInputStream = new FileInputStream(fd);
        mOutputStream = new FileOutputStream(fd);
    }
    isOpen = true;
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:11,代码来源:AdkPort.java

示例11: connectToDevice

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
/**
 * Connect to a device.
 * @return Status of the UsbConnection.
 */
public Status connectToDevice(){
    if(status != Status.PERMISSION_REQUESTED && status != Status.CONNECTED){
        UsbAccessory[] accessoryList = usbManager.getAccessoryList();
        if(accessoryList == null) {
            setStatus(Status.DISCONNECTED);
            return status;
        }
        accessory = accessoryList[0];
        usbManager.requestPermission(accessory, permissionIntent);
        setStatus(Status.PERMISSION_REQUESTED);
    }
    return status;
}
 
开发者ID:WIStudent,项目名称:Android-Raspberry-Pi-Keyboard,代码行数:18,代码来源:UsbConnection.java

示例12: addUsbToJson

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public static void addUsbToJson(UsbAccessory usbAccessory, JSONObject json){
    try {
        json.put("serial", usbAccessory.getSerial());
        json.put("uri", usbAccessory.getUri());
        json.put("hashCode", usbAccessory.hashCode());
    }catch(JSONException e){
    }
}
 
开发者ID:GIGATeam,项目名称:UsbExtension,代码行数:9,代码来源:UsbEvent.java

示例13: usbAccessories

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public ArrayList<UsbAccessory> usbAccessories(){
    if(_usbAccessories==null){
        _usbAccessories = new ArrayList<UsbAccessory>();
        UsbManager usbManager = getUsbManager();
        UsbAccessory accessories[] = usbManager.getAccessoryList();
        if(accessories==null){
            return _usbAccessories;
        }
        for(Integer i=0;i<accessories.length;i++){
            _usbAccessories.add(accessories[i]);
        }
    }
    return _usbAccessories;
}
 
开发者ID:GIGATeam,项目名称:UsbExtension,代码行数:15,代码来源:UsbContext.java

示例14: type

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public static SubjectFactory<UsbAccessorySubject, UsbAccessory> type() {
  return new SubjectFactory<UsbAccessorySubject, UsbAccessory>() {
    @Override
    public UsbAccessorySubject getSubject(FailureStrategy fs, UsbAccessory that) {
      return new UsbAccessorySubject(fs, that);
    }
  };
}
 
开发者ID:pkware,项目名称:truth-android,代码行数:9,代码来源:UsbAccessorySubject.java

示例15: OpenAccessory

import android.hardware.usb.UsbAccessory; //导入依赖的package包/类
public boolean OpenAccessory(UsbAccessory accessory)
{
    fileDescriptor = usbmanager.openAccessory(accessory);

    if(fileDescriptor != null)
    {
        PodEmuLog.debug("FT31xD: file descriptor successfully opened");
        usbAccessory = accessory;

        FileDescriptor fd = fileDescriptor.getFileDescriptor();

        inputStream  = new FileInputStream(fd);
        outputStream = new FileOutputStream(fd);

        /* check if any of them are null */
        if(inputStream == null || outputStream==null)
        {
            PodEmuLog.error("FT31xD: sth went wrong. In or Out descriptor is null!");
            return false;
        }
    }
    else
    {
        PodEmuLog.error("FT31xD: fileDescriptor is null!");
        return false;
    }
    return true;
}
 
开发者ID:xtensa,项目名称:PodEmu,代码行数:29,代码来源:SerialInterface_FT31xD.java


注:本文中的android.hardware.usb.UsbAccessory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。