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();
}
}
您可以發佈您的logcat? – Shrikant
上面的代碼沒有錯誤,但也沒有顯示圖像但是,當我使用它在oncreate它工作,但我希望它在onActivityResult – Nitin
工作@Shrikant你可以給任何教程或任何其他提示如何才能實現相同 – Nitin