【问题标题】:Capture image is not able to store in SD card? [closed]捕获的图像无法存储在 SD 卡中? [关闭]
【发布时间】:2014-09-02 19:08:28
【问题描述】:

当我单击按钮时,相机正在捕获图像但无法保存在 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())));
}
}`

【问题讨论】:

  • 调用 finish() 应该会引导您回到之前的活动。你不应该让用户点击返回按钮
  • 如何启用或禁用手机返回键?
  • 无法禁用后退按钮
  • 但是如何启用呢?有什么方法吗?
  • 您可以覆盖 OnbackPressed。但是您应该考虑重新设计而不是解决方法

标签: android button android-emulator


【解决方案1】:
  • 转到 AVD 管理器。
  • 编辑您的设备。
  • 选择具有动态硬件控件的皮肤。
  • 取消选中存在的硬件键盘(或 Escape in keyboard=Back 按钮)

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      相关资源
      最近更新 更多