File root=new File(Environment.getExternalStorageDirectory()
+ File.separator + "MYPICS" + File.separator);
File sdImageMainDirectory ;
if (!root.exists()) {
root.mkdirs();
}
ImageButton cam =(ImageButton)findViewById(R.id.ImageButton1);
cam.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
imageName = "MyPic" + i + ".png";
sdImageMainDirectory = new File(root, imageName);
Uri imgUri = Uri.fromFile(sdImageMainDirectory);
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
startActivityForResult(intent, 0);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) {
case 0:
// finish();
break;
case -1:
files = root.listFiles();
count = files.length;
try {
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 2;
bm = BitmapFactory.decodeFile(root.getPath()+"/"+imageName,option);
ImageView imageview =(ImageView)findViewById(R.id.imageView1);
imageview .setImageBitmap(bm);
}
} catch (Exception e) {
e.printStackTrace();
}
}