動画を撮影する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
注: このページでは、サポートが終了した Camera クラスについて言及していますが、CameraX(特定のユースケースでは Camera2)の使用をおすすめします。CameraX と Camera2 は、どちらも Android 5.0(API レベル 21)以降に対応しています。
このレッスンでは、既存のカメラアプリを使用して動画を撮影する方法について説明します。
アプリには実行すべきジョブがあり、動画の統合はそのごく一部にすぎません。動画の撮影は最小限の操作で行えるようにし、カムコーダーを作り変えずに済むようにします。幸い、ほとんどの Android デバイスには、動画を撮影するためのカメラアプリがあらかじめインストールされています。このレッスンでは動画の撮影を行います。
カメラ機能をリクエストする
アプリにカメラが必要なことを示すには、マニフェスト ファイルに <uses-feature>
タグを追加します。
<manifest ... >
<uses-feature android:name="android.hardware.camera"
android:required="true" />
...
</manifest>
アプリでカメラを使用するものの、アプリが動作するうえでカメラが必要ない場合は、android:required
を false
に設定します。そうすることで、カメラを搭載していないデバイスでも Google Play でアプリをダウンロードできるようになります。次に、hasSystemFeature(PackageManager.FEATURE_CAMERA)
を呼び出して、実行時にカメラを使用できるかどうかを確認する必要があります。カメラを使用できない場合は、カメラ機能を無効にする必要があります。
動画を見る
Android カメラアプリは、ストレージ内の動画の場所を指す Uri
として onActivityResult()
に提供された Intent
で動画を返します。次のコードでは、その動画を取得して VideoView
に表示しています。
Kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
val videoUri: Uri = intent.data
videoView.setVideoURI(videoUri)
}
}
Java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Uri videoUri = intent.getData();
videoView.setVideoURI(videoUri);
}
}
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[],[],null,["# Record videos\n\n**Note:** This page refers to the\n[Camera](/reference/android/hardware/Camera) class, which is deprecated. We\nrecommend using [CameraX](/media/camera/camerax) or, for specific use cases,\n[Camera2](/media/camera/camera2). Both CameraX and Camera2 support Android 5.0\n(API level 21) and higher.\n\nThis lesson explains how to capture video using existing camera\napplications.\n\nYour application has a job to do, and integrating videos is only a small\npart of it. You want to take videos with minimal fuss, and not reinvent the\ncamcorder. Happily, most Android-powered devices already have a camera application that\nrecords video. In this lesson, you make it do this for you. \n\nRefer to the following related resources:\n\n- [Camera](/guide/topics/media/camera)\n- [Intents and Intent\n Filters](/guide/components/intents-filters)\n\nRequest the camera feature\n--------------------------\n\nTo advertise that your application depends on having a camera, put a\n`\u003cuses-feature\u003e` tag in the manifest file: \n\n```xml\n\u003cmanifest ... \u003e\n \u003cuses-feature android:name=\"android.hardware.camera\"\n android:required=\"true\" /\u003e\n ...\n\u003c/manifest\u003e\n```\n\nIf your application uses, but does not require a camera in order to function, set `android:required` to `false`. In doing so, Google Play will allow devices without a\ncamera to download your application. It's then your responsibility to check for the availability\nof the camera at runtime by calling [hasSystemFeature(PackageManager.FEATURE_CAMERA)](/reference/android/content/pm/PackageManager#hasSystemFeature(java.lang.String)).\nIf a camera is not available, you should then disable your camera features.\n\nView the video\n--------------\n\nThe Android Camera application returns the video in the [Intent](/reference/android/content/Intent) delivered\nto [onActivityResult()](/reference/android/app/Activity#onActivityResult(int, int, android.content.Intent)) as a [Uri](/reference/android/net/Uri) pointing to the video location in storage. The following code\nretrieves this video and displays it in a [VideoView](/reference/android/widget/VideoView). \n\n### Kotlin\n\n```kotlin\noverride fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent) {\n if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {\n val videoUri: Uri = intent.data\n videoView.setVideoURI(videoUri)\n }\n}\n```\n\n### Java\n\n```java\n@Override\nprotected void onActivityResult(int requestCode, int resultCode, Intent intent) {\n if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {\n Uri videoUri = intent.getData();\n videoView.setVideoURI(videoUri);\n }\n}\n```"]]