2014-07-12 102 views
-3

当我点击按钮,相机拍摄照片,但不能以SD保存card.please检查这个code.if我没有任何错误捕获的图像无法存储在SD卡中?

` ImgPhoto =(ImageView的)findViewById(R.id.imageView1 );

BtnSelectImage = (Button) findViewById(R.id.button1); 
    BtnSelectImage.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      // TODO Auto-generated method stub 
      try { 
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(), "Couldn't load photo", Toast.LENGTH_LONG).show(); 
      } 
     } 
    }); 

} 
    private void SaveIamge(Bitmap finalBitmap) { 

    String root = Environment.getExternalStorageDirectory().toString(); 
    File file1=new File(Environment.getExternalStorageDirectory()+File.separator+"image.jpeg"); 
    File myDir = new File(root + "/sdcard/");  
    myDir.mkdirs(); 
    Random generator = new Random(); 
    int n = 10000; 
    n = generator.nextInt(n); 
    String fname = "Image-"+ n +".jpeg"; 
    File file = new File (myDir, fname); 
    if (file.exists()) file.delete(); 
    try { 
      FileOutputStream out = new FileOutputStream(file); 
      finalBitmap.compress(Bitmap.CompressFormat.PNG, 90, out); 
      out.flush(); 
      out.close(); 

    } catch (Exception e) { 
      e.printStackTrace(); 
    } 
    sendBroadcast(new Intent(
      Intent.ACTION_MEDIA_MOUNTED, 
         Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 
} 
}` 
+0

调用完成()应该带领你回到过去的活动。你应该不让用户点击返回按钮 – Raghunandan

+0

如何启用或禁用手机后退按钮? – Guru

+0

不可能禁用后退按钮 – Raghunandan

回答

1

当按下后退按钮,当前活动的onBackPressed()方法被调用。默认行为是完成活动。您不需要执行任何操作即可启用此行为。

1
  • 转到AVD管理器。
  • 编辑您的设备。
  • 使用动态硬件控件选择皮肤。
  • 取消选中硬件键盘存在(或键盘逃生=后退按钮)
相关问题