在java中这是什么类型的变量声明(What type of variable declaration is this in java)
class FreshJuice { enum FreshJuiceSize{ SMALL, MEDIUM, LARGE } FreshJuiceSize size; }
什么类型的变量是
size
?是
FreshJuiceSize size;
将size
声明为实例变量的shorhand方式?class FreshJuice { enum FreshJuiceSize{ SMALL, MEDIUM, LARGE } FreshJuiceSize size; }
What type of variable is
size
?Is
FreshJuiceSize size;
a shorhand way of declaringsize
as a instance variable ?
原文:https://stackoverflow.com/questions/41821812
更新时间:2022-01-02 14:01
最满意答案
您必须通过usb manager连接usb,这应该在获得该usb的许可后发生
UsbManager manager = (UsbManager) this.getSystemService(Context.USB_SERVICE); UsbDeviceConnection connection = manager.openDevice(device);
获取接口和端点
UsbEndpoint epIN = null; UsbEndpoint epOUT = null; UsbInterface usbIf = dev.getInterface(0); // inter will change according to usb 0/1 etc.. for (int i = 0; i < usbIf.getEndpointCount(); i++) { if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK){ if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) epIN = usbIf.getEndpoint(i); else epOUT = usbIf.getEndpoint(i); } else { Log.d("USB","Not Bulk"); } }
将文本传输到usb
byte[] str = get.getBytes("TEXT"); connection.bulkTransfer(epOUT, str, str.length, 500);
希望能帮助到你。
You have to connect the usb via usb manager this should happen after permission granted for that usb
UsbManager manager = (UsbManager) this.getSystemService(Context.USB_SERVICE); UsbDeviceConnection connection = manager.openDevice(device);
get Interface and End points
UsbEndpoint epIN = null; UsbEndpoint epOUT = null; UsbInterface usbIf = dev.getInterface(0); // inter will change according to usb 0/1 etc.. for (int i = 0; i < usbIf.getEndpointCount(); i++) { if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK){ if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) epIN = usbIf.getEndpoint(i); else epOUT = usbIf.getEndpoint(i); } else { Log.d("USB","Not Bulk"); } }
Transfer text to usb
byte[] str = get.getBytes("TEXT"); connection.bulkTransfer(epOUT, str, str.length, 500);
hope it helps.
相关问答
更多-
如何从外部USB设备获取数据到Android应用程序?(How to get data from external USB device to android application?)[2023-02-15]
不是直接的:但是,这可能会让你做你想做的事。 http://www.sparkfun.com/products/10585 它是USB主机控制器和Android API的组合,使用ADB协议传递数据。 或者,你也可以看看这个: http://code.google.com/p/microbridge/ 这需要一个Arduino,似乎并不是那么干净整合,但也应该做你想要的。 Not directly: however, this will probably let you do what you want. ... -
在我们公司,我们使用以下代码打开具有特定ID的设备。 此外,它只适用于OTG兼容设备。 在你的Manifest中,你不需要USB_DETACHED,因为清单中的意图过滤器意味着打开/启动你的应用程序,除非你想在usb分离时打开你的apk。 只需点击ConnectUSB即可; UsbInterface usbInterface; UsbEndpoint usbEndpointIN, usbEndpointOUT; UsbDeviceConnection usbDeviceConnect ...
-
为了将一些数据写入USB,我们需要 uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" 通过引用一些链接,我知道上述权限可以由设备的提供商获得。 所以我们可以应用上述机制来完成它。 In order to write some data to USB, we need uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" By re ...
-
好的,我发现了问题。 问题来自于o2.getID()参数给出的方法copy.copyFromPortableDeviceToHost 。 因为o2代表文件夹,而不是文件夹中的文件,所以不可能发送文件夹,为了成功我需要在文件夹中发送文件。 所以我将我的PortableDeviceObject o2转换为PortableDeviceFolderObject ,以便在表示文件的PortableDeviceFolderObject中获取带有targetFolder.getChildObjects()的子Object ...
-
Android客户端应用程序(可能通过USB使用ADB)(Android Client Application (Possibly using ADB through USB))[2022-07-11]
如果您想将计算机上的TCP端口8001转发到手机上的端口8001,则可以使用以下命令: adb forward tcp:8001 tcp:8001 如果需要,您可以更改手机或设备上的端口。 该命令的文档位于以下位置: http : //developer.android.com/guide/developing/tools/adb.html#forwardports 至于为什么这不应该工作 - 有一些信息从你的问题中遗漏。 这些只是标准的TCP套接字。 Java版本不应该有任何区别,所以我不明白你的问题。 ... -
我找到了解决方案: 首先,我植根我的Android设备。 然后我在etc / permissions文件夹中添加了一个名为android.hardware.usb.host.xml的文件,其中包含权限
-
通过USB发送数据的Android应用程序[重复](An Android Application that Sends data through USB [duplicate])[2022-05-23]
您必须通过usb manager连接usb,这应该在获得该usb的许可后发生 UsbManager manager = (UsbManager) this.getSystemService(Context.USB_SERVICE); UsbDeviceConnection connection = manager.openDevice(device); 获取接口和端点 UsbEndpoint epIN = null; UsbEndpoint epOUT = null; UsbInterface usb ... -
在Usb主机模式下将数据从android发送到连接的Usb存储设备(Send data from android to connected Usb storage device in Usb Host Mode)[2022-08-30]
您正在搜索批量端点,这意味着您正尝试使用BBB进行扇区读/写(请参阅大规模存储类BBB的USB规范)。 Now I need to create a file on the connected flash drive and save some data in the file. 使用端点执行扇区读/写,但您必须在其上编写文件系统驱动程序(如FAT32或EXT4等)。 文件创建是文件系统操作,而不是扇区级读/写。 Is there a way to create a file on connected de ... -
我有同样的问题,答案不是那么知道。 简而言之,您必须使用adb和端口转发。 有关更多详细信息,您可以使用此链接。 通过usb将android连接到电脑 希望它有效! ;) I had same problem, answer is not that known. In short you must use adb and port forwarding. for more detail you can use this link. Connecting android to the pc over usb ...
-
Android应用程序通过USB电缆的数据引脚发送信号(android app to send a signal through the data pin of the usb cable)[2024-01-04]
与一些较旧的端口设计(串行和并行端口)不同,USB不提供任何任意电气控制。 每个引脚都支持USB协议中的特定功能,不能任意设置。 某些设备可能支持切换到备用非USB模式,但几乎所有这些模式同样不允许直接控制。 如果您的Android手机支持USB主机模式,则可以连接USB串行(RS232)适配器。 它有两个可任意设置的控制引脚,RTS和DTR,以及实际的串行数据线。 Unlike some older port designs (serial and parallel ports), USB does no ...