Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Android handy notes-how to write the code for photos, videos and audio recordings

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail about Android handwritten notes-photo and video recordings and how to write the code. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Package com.cons.dcg.collect;import java.io.File;import java.text.SimpleDateFormat;import java.util.*;import android.app.*;import android.content.Intent;import android.database.Cursor;import android.net.Uri;import android.os.AsyncTask;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore;import android.view.*;import android.widget.*;public class RecordActivity extends Activity implements OnClickListener {private static final int RESULT_CAPTURE_IMAGE = 1 / / requestCode private static final int REQUEST_CODE_TAKE_VIDEO of the photograph = 2 requestCode private String strImgPath of the camera / requestCode private static final int RESULT_CAPTURE_RECORDER_SOUND = 3 of the camera / requestCode private String strImgPath of the recording; / / absolute path of the photo file private String strVideoPath = ""; / / absolute path of the video file private String strRecorderPath = "" / / absolute path to the recording file @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); this.setContentView (R.layout.problem_report);} @ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {super.onActivityResult (requestCode, resultCode, data) Switch (requestCode) {case RESULT_CAPTURE_IMAGE:// photo if (resultCode = = RESULT_OK) {Toast.makeText (this, strImgPath, Toast.LENGTH_SHORT). Show ();} break Case REQUEST_CODE_TAKE_VIDEO:// shoots video if (resultCode = = RESULT_OK) {Uri uriVideo = data.getData (); Cursor cursor=this.getContentResolver () .query (uriVideo, null, null) If (cursor.moveToNext ()) {/ * * _ data: absolute path to the file, _ display_name: file name * / strVideoPath = cursor.getString (cursor.getColumnIndex ("_ data")) Toast.makeText (this, strVideoPath, Toast.LENGTH_SHORT). Show ();}} break Case RESULT_CAPTURE_RECORDER_SOUND:// recording if (resultCode = = RESULT_OK) {Uri uriRecorder = data.getData (); Cursor cursor=this.getContentResolver () .query (uriRecorder, null, null) If (cursor.moveToNext ()) {/ * * _ data: absolute path to the file, _ display_name: file name * / strRecorderPath = cursor.getString (cursor.getColumnIndex ("_ data")) Toast.makeText (this, strRecorderPath, Toast.LENGTH_SHORT). Show ();}} break }} / * Photographic function * / private void cameraMethod () {Intent imageCaptureIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE); strImgPath = Environment.getExternalStorageDirectory (). ToString () + "/ CONSDCGMPIC/" / / folder String fileName = new SimpleDateFormat ("yyyyMMddHHmmss") .format (new Date ()) + ".jpg"; / / name File out = new File (strImgPath); if (! out.exists ()) {out.mkdirs ();} out = new File (strImgPath, fileName) StrImgPath = strImgPath + fileName;// the absolute path of the photo Uri uri = Uri.fromFile (out); imageCaptureIntent.putExtra (MediaStore.EXTRA_OUTPUT, uri); imageCaptureIntent.putExtra (MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult (imageCaptureIntent, RESULT_CAPTURE_IMAGE) } / * Video shooting * / private void videoMethod () {Intent intent = new Intent (MediaStore.ACTION_VIDEO_CAPTURE); intent.putExtra (MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult (intent, REQUEST_CODE_TAKE_VIDEO) } / * recording function * / private void soundRecorderMethod () {Intent intent = new Intent (Intent.ACTION_GET_CONTENT); intent.setType ("audio/amr"); startActivityForResult (intent, RESULT_CAPTURE_RECORDER_SOUND) } / * prompt * @ param text * @ param duration * / private void showToast (String text, int duration) {Toast.makeText (ProblemReport.this, text, duration) .show () }} on the Android handwritten-photo video and recording code how to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report