本文整理汇总了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);
}
}
}
示例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");
}
}
示例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;
}
示例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;
}
}
}
}
}
示例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();
}
}
}
};
}
示例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]);
}
}
示例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);
}
}
示例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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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){
}
}
示例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;
}
示例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);
}
};
}
示例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;
}