New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@consolecodea/react-native-mtp-camera

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@consolecodea/react-native-mtp-camera

get live image from nikon or canon camera to mobile through usb

  • 0.2.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

react-native-mtp-camera

get live image from nikon or canon camera to mobile through usb (Android only)

npm version appveyor MIT License

Installation

npm install @consolecodea/react-native-mtp-camera

Android Setup

Permissions

To integrate react-native-mtp-camera into your Android project, follow these steps to configure your Android manifest:

  • Open Your Android Manifest File: Navigate to your Android project's android/app/src/main/AndroidManifest.xml file.
  • Add Permissions: Ensure the following permissions are included within the tag:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

These permissions are required for network communication, notifications, and running services in the foreground.

  • Declare USB Host Feature: Add the USB host feature declaration. This is essential for communicating with USB devices:
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
  • Configure MainActivity: Update your tag for the MainActivity to handle USB device attachments and set launch configuration:
<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>
  • Create a new file named device_filter.xml under android/app/src/main/res/xml/ (if it doesn't exist already), and paste the following content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <usb-device class="6" />
</resources>
  • Add ImageLoadingService: If your package includes a service (e.g., ImageLoadingService), declare it within the tag:
<service
    android:name="com.mtpcamera.ImageLoadingService"
    android:foregroundServiceType="dataSync" />

Explanation:

  • Permissions: Make sure to explain any critical permissions required by your package, such as INTERNET, POST_NOTIFICATIONS, and FOREGROUND_SERVICE. These are already included in your manifest.
  • Manifest Updates: Provide a clear overview of how to integrate your package into an existing Android project, highlighting key aspects like MainActivity setup, USB device attachment handling, and the ImageLoadingService.

This updated README will help users understand how to configure their Android projects to work with your react-native-mtp-camera package effectively.

Usage

import {
  startService,
  stopService,
  cameraEventLister,
  type cameraEventProps,
} from '@consolecodea/react-native-mtp-camera';
import { NativeEventEmitter } from 'react-native';
const eventEmitter = new NativeEventEmitter();

// Start the image loading service
startService()
  .then(() => {
    console.log('Service started');
  })
  .catch((error) => {
    console.error('Failed to start service:', error);
  });

// Stop the image loading service
stopService()
  .then(() => {
    console.log('Service stopped');
  })
  .catch((error) => {
    console.error('Failed to stop service:', error);
  });

// Listen for new images
  eventEmitter.addListener(
      cameraEventLister.onNewImage,
      (event: cameraEventProps) => {
        setImage(event.imagePath);
      }
    );


// Remember to remove the listener when it's no longer needed
 return () => {
      eventEmitter.removeAllListeners(cameraEventLister.onNewImage);
    };

Props

MethodDescription
startService()Starts the image loading service.
stopService()Stops the image loading service.

Event Listeners

ListenerDescription
cameraEventLister.onNewImageTriggered when a new image is received.

Event Properties

PropertyDescription
cameraEventProps.imagePathImage file uri.
cameraEventProps.imageBase64Image base64.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Keywords

FAQs

Package last updated on 28 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc