@@ -61,7 +61,32 @@ Add USB permissions to your `AndroidManifest.xml`:
6161<uses-permission android : name =" android.permission.USB_PERMISSION" />
6262<uses-feature android : name =" android.hardware.usb.host" />
6363```
64+ ## Setup: Auto-Launch App
6465
66+ To make your app open automatically when the hardware is plugged in:
67+
68+ ### 1. Define Device Filter
69+ Create ` res/xml/device_filter.xml ` :
70+ ``` xml
71+ <?xml version =" 1.0" encoding =" utf-8" ?>
72+ <resources >
73+ <!-- Empty tag matches any USB Serial device -->
74+ <usb-device />
75+ </resources >
76+ ```
77+
78+ ### 2. Configure Manifest
79+ Update your ` MainActivity ` in ` AndroidManifest.xml ` :
80+ ``` xml
81+ <activity android : name =" .MainActivity" android : exported =" true" >
82+ <intent-filter >
83+ <action android : name =" android.hardware.usb.action.USB_DEVICE_ATTACHED" />
84+ </intent-filter >
85+ <meta-data
86+ android : name =" android.hardware.usb.action.USB_DEVICE_ATTACHED"
87+ android : resource =" @xml/device_filter" />
88+ </activity >
89+ ```
6590## Quick Start
6691
6792### Basic Device Enumeration
@@ -76,9 +101,9 @@ import {
76101const devices: UsbDevice [] = getDeviceList ();
77102
78103devices .forEach (device => {
79- console .log (` Device: ${device .productName } ` );
80104 console .log (` Vendor ID: ${device .vendorId } ` );
81105 console .log (` Product ID: ${device .productId } ` );
106+ console .log (` Manufacturer: ${device .manufacturer } ` );
82107});
83108```
84109
@@ -127,8 +152,8 @@ import {
127152 onReadInterval ,
128153 offReadInterval ,
129154 type RawReadConfig ,
130- NativeEventEmitter ,
131155} from ' @rejaul/react-native-usb-serial' ;
156+ import {NativeEventEmitter } from ' react-native' ;
132157
133158// Configure reading parameters
134159const readConfig: RawReadConfig = {
@@ -200,7 +225,7 @@ async function readSerialData(): Promise<void> {
200225
201226## Advanced Usage
202227
203- ### Soil Sensor Integration
228+ ### Soil Sensor Integration 8-in-1 (Modbus RTU)
204229
205230``` typescript
206231import {
@@ -209,8 +234,8 @@ import {
209234 offReadSoilDataInterval ,
210235 type SoilSensorConfig ,
211236 type SoilData ,
212- NativeEventEmitter ,
213237} from ' @rejaul/react-native-usb-serial' ;
238+ import {NativeEventEmitter } from ' react-native' ;
214239
215240// Configure modbus soil sensor
216241const soilConfig: SoilSensorConfig = {
@@ -311,12 +336,9 @@ async function safeConnect(device: UsbDevice): Promise<void> {
311336
312337``` typescript
313338type UsbDevice = {
314- deviceName: string ;
315339 vendorId: number ;
316340 productId: number ;
317341 manufacturer? : string | null ;
318- productName? : string | null ;
319- serialNumber? : string | null ;
320342};
321343```
322344
0 commit comments