开发者

Camera intent android

开发者 https://www.devze.com 2023-02-18 06:14 出处:网络
When I begin the camera intent I give it a file na开发者_JAVA技巧me I would like it to use. When I get this on the phone it uses the phones default file name. Which is no help as I need the image name

When I begin the camera intent I give it a file na开发者_JAVA技巧me I would like it to use. When I get this on the phone it uses the phones default file name. Which is no help as I need the image name later in the app.

Camera intent code...

public void onClick(View view) {
  String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
  System.out.println(currentDateTimeString); 
  filename = ("/sdcard/" + currentDateTimeString + ".jpg");

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  File file = new File(Environment.getExternalStorageDirectory(), filename);

  outputFileUri = Uri.fromFile(file);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
  startActivityForResult(intent, TAKE_PICTURE);
  filetype = "image/jpeg";

}


James,

Here is the function I use to capture an image and save it to a location of my choosing (sub folder with my app name).

public void imageFromCamera() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
        Log.d(TAG, "No SDCARD");
    } else {
        mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",  
            "PIC"+System.currentTimeMillis()+".jpg");
        mTempImagePath = mImageFile.getAbsolutePath();
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
        startActivityForResult(intent, TAKE_PICTURE);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号