android camera以时间来命名照片文件

当我们拍照时一般都由Android自动设置文件名,而已我们一般都是用时间来命名文件,以防止出现一样的文件名而覆盖了原来的文件。

所以有核心代码为:

//得到当前系统时间
        Time t=new Time();
        t.setToNow();
        int year=t.year;
        int month=t.month;
        int day=t.monthDay;
        int hour=t.hour;
        int minute=t.minute;
        int second=t.second;
        Log.i(TAG, ""+year+month+day+hour+minute+second);
        String filename=""+year+month+day+hour+minute+second;
        //得到SD卡的路径也设置文件名
        //这里可以简化的写成imageFilePath=Uri.parse("file:////sdcard/my.jpg");
        /*imageFilePath=Environment.getExternalStorageDirectory()
                .getAbsolutePath()+"/my01.jpg";*/
        imageFilePath=Environment.getExternalStorageDirectory()
                .getAbsolutePath()+"/"+filename+".jpg";
        //创建文件
        File file=new File(imageFilePath);
        //格式化为Uri
        Uri fileImageFilePath=Uri.fromFile(file);
        view=(ImageView)findViewById(R.id.imageview);
        Intent i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);//启动intent
        //设置到意图中
        i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, fileImageFilePath);
        startActivityForResult(i, CAMERA_RESULT);
找一个博客做自己的女朋友,不管你跟她说什么她都帮你记录,这是多么幸福的一件事啊。如果有女生能做到这点,赶尽娶回家吧!
原文地址:https://www.cnblogs.com/hexiaochun/p/2712144.html