相机意图安卓 [英] Camera intent android

查看:189
本文介绍了相机意图安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始拍照意图我给它一个文件名,我想它的使用。当我得到这个在手机上使用手机默认的文件名。这是毫无帮助,我以后需要在应用程序中的图像名称。

相机意图code ...

 公共无效的onClick(视图查看){
  字符串currentDateTimeString = DateFormat.getDateInstance()格式(新的Date())。
  的System.out.println(currentDateTimeString);
  文件名=(/ SD卡/+ currentDateTimeString +.JPG);

  意向意图=新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
  档案文件=新的文件(Environment.getExternalStorageDirectory(),文件名);

  outputFileUri = Uri.fromFile(文件);
  intent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri);
  startActivityForResult(意向,TAKE_PICTURE);
  文件类型=图像/ JPEG;

}
 

解决方案

詹姆斯,

下面是我用它来拍摄图像,并把它保存到我的选择(子文件夹我的应用程序的名称)。

的位置功能

 公共无效imageFromCamera(){
    意向意图=新的意图(android.media.action.IMAGE_CAPTURE);
    如果(!Environment.getExternalStorageState()。等于(Environment.MEDIA_MOUNTED)){
        Log.d(TAG,无SD卡);
    } 其他 {
        mImageFile =新的文件(Environment.getExternalStorageDirectory()+文件分割符+MyApp的,
            PIC+ System.currentTimeMillis的()+JPG);
        mTempImagePath = mImageFile.getAbsolutePath();
        intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(mImageFile));
        startActivityForResult(意向,TAKE_PICTURE);
    }
}
 

When I begin the camera intent I give it a file name 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);
    }
}

这篇关于相机意图安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆