@capacitor/camera
カメラAPIは、カメラで写真を撮影したり、フォトアルバムから既存の写真を選択する機能を提供します。
Install
npm install @capacitor/camera
npx cap sync
iOS
iOS requires the following usage description be added and filled out for your app in Info.plist
:
NSCameraUsageDescription
(Privacy - Camera Usage Description
)NSPhotoLibraryAddUsageDescription
(Privacy - Photo Library Additions Usage Description
)NSPhotoLibraryUsageDescription
(Privacy - Photo Library Usage Description
)
Read about Configuring Info.plist
in the iOS Guide for more information on setting iOS permissions in Xcode
Android
When picking existing images from the device gallery, the Android Photo Picker component is now used. The Photo Picker is available on devices that meet the following criteria:
- Run Android 11 (API level 30) or higher
- Receive changes to Modular System Components through Google System Updates
Older devices and Android Go devices running Android 11 or 12 that support Google Play services can install a backported version of the photo picker. To enable the automatic installation of the backported photo picker module through Google Play services, add the following entry to the <application>
tag in your AndroidManifest.xml
file:
<!-- Trigger Google Play services to install the backported photo picker module. -->
<!--suppress AndroidDomInspection -->
<service android:name="com.google.android.gms.metadata.ModuleDependencies"
android:enabled="false"
android:exported="false"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
</intent-filter>
<meta-data android:name="photopicker_activity:0:required" android:value="" />
</service>
If that entry is not added, the devices that don't support the Photo Picker, the Photo Picker component fallbacks to Intent.ACTION_OPEN_DOCUMENT
.
The Camera plugin requires no permissions, unless using saveToGallery: true
, in that case the following permissions should be added to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You can also specify those permissions only for the Android versions where they will be requested:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29"/>