Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 錄像,攝影自定義保存的文件名稱

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);
   }

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved