当前位置:操作系统 > 安卓/Android >>

android 录像,摄影自定义保存的文件名称

public class TestActivity extends Activity {
   
    public static final int NONE = 0;

    public static final int REQUEST_CODE_TAKE_VIDEO = 4;// 摄像的照相的
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
  Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
  intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); 
  startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);

    }
   
    @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == NONE)
     return;
    if (data == null)
     return;
    //录像
    if(requestCode == REQUEST_CODE_TAKE_VIDEO)
    {
     if (resultCode == RESULT_OK) {
                         Uri uriVideo = data.getData();
                         Cursor cursor = this.getContentResolver().query(uriVideo, null, null, null, null);
                         if (cursor.moveToNext()) {
                                 /* _data:文件的绝对路径 ,_display_name:文件名 */
                                 String strVideoPath = cursor.getString(cursor.getColumnIndex("_data"));
                                 Toast.makeText(this, strVideoPath, Toast.LENGTH_SHORT).show();
                                
                                 String videoPath = "111111113.3gp";
                           Date now = new Date();//声明一个日期[当前日期]
                           SimpleDateFormat f2 = new SimpleDateFormat("yyyyMMdd");//添加不同的参数,显示不同格式的日期
                           SimpleDateFormat f3= new SimpleDateFormat("HHmmss");//显示时间这里显示的是24小时制 + "_" +
                           videoPath = "王晓丽" + "广州段#" + f2.format(now) + "_" + f3.format(now) + ".3gp";
                                
                                 //在这里替换下文件名称,改成你想要的名称
                                 File file = new File(strVideoPath);
                                 String pFile = file.getParentFile().getPath() + "/"; 
                                 String newPath = pFile + videoPath; 
                                 file.renameTo(new File(newPath));

                         }
     }


    }
    super.onActivityResult(requestCode, resultCode, data);
   }

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,