-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Hello,
I am encountering an issue while using the @consolecodea/react-native-mtp-camera library in my React Native project. When trying to connect to the USB device (DSLR camera), I am getting the error message 'USB device not found'.
I have already added the necessary permissions in the AndroidManifest.xml file, as shown below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.USB_PERMISSION"/>
<uses-permission android:name="android.permission.MANAGE_USB" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<!-- Main launcher intent filter -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Intent filter for USB device attached -->
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<!-- Metadata for USB device filter -->
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
<service
android:name="com.mtpcamera.ImageLoadingService"
android:foregroundServiceType="dataSync" />
</application>
</manifest>
Here’s the relevant code from page.js:
import React, { useState, useEffect } from 'react';
import { View, Text, FlatList, Button, NativeEventEmitter } from 'react-native';
import MTPCamera, {
startService,
stopService,
cameraEventLister,
cameraEventProps
} from '@consolecodea/react-native-mtp-camera';
const App = () => {
const [files, setFiles] = useState([]);
const eventEmitter = new NativeEventEmitter();
useEffect(() => {
const fetchFiles = async () => {
try {
console.log('-- TEST --');
} catch (error) {
console.error('Error fetching files: ', error);
}
};
fetchFiles();
eventEmitter.addListener(
cameraEventLister.onNewImage,
(event) => {
console.log('Get new photo', event.imagePath);
}
);
}, []);
return (
<View>
<Button
title="Run"
onPress={() => {
startService()
.then(() => {
console.log('Service started');
})
.catch((error) => {
console.error('Failed to start service:', error);
});
}}
/>
<Button
title="Stop"
onPress={() => {
stopService()
.then(() => {
console.log('Service stopped');
})
.catch((error) => {
console.error('Failed to stop service:', error);
});
}}
/>
<FlatList
data={files}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<View>
<Text>{item.name}</Text>
</View>
)}
/>
</View>
);
};
export default App;
Despite having these permissions and code in place, I continue to see the 'USB device not found' error. Any help or suggestions would be appreciated.
Metadata
Metadata
Assignees
Labels
No labels