Reputation: 41
in my application I need to capture some images and save them in a folder with the option to rename it. Thanks for your help and sorry for my bad English ..... and I tried that but it does not work, it saves just one image even snap more photos, why? thanks :D
public class TestPress extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prova);
final String direct = this.getIntent().getStringExtra("key");
// TODO Auto-generated method stub
Button p = (Button) findViewById(R.id.button2);
p.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent camera= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri uriSavedImage=Uri.fromFile(new File("/sdcard/CameraTest/flashCropped.png"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera, 1);
}
});
Button np = (Button) findViewById(R.id.button3);
np.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent next = new Intent(Press.this, CameraActivity.class);
startActivity(next);
}
});
}
}
Upvotes: 0
Views: 5369
Reputation: 224
private void doTakePhotoAction() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// 创建目录
File fileDir = new File(Environment.getExternalStorageDirectory()
+ "/zuijiao");
if (!fileDir.exists()) {
fileDir.mkdirs();
}
// 拍照后的路径
imagePath = Environment.getExternalStorageDirectory() + "/zuijiao/"
+ System.currentTimeMillis() + ".jpg";
carmeraFile = new File(imagePath);
imageCarmeraUri = Uri.fromFile(carmeraFile);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
imageCarmeraUri);
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, ACTION_TAKE_CARMERA);
} catch (ActivityNotFoundException e) {
// Do nothing for now
}
}
and pls check the save file length, if length equal 0,you should delete it(some people open the camera but don't take a photo,there will have a empty file,delete it)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACTION_TAKE_CARMERA)
{
}
}
you can do something after photo taken in this function.
there also have other ways to do this
Upvotes: 1