2014-07-12 163 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管理器。
  • 編輯您的設備。
  • 使用動態硬件控件選擇皮膚。
  • 取消選中硬件鍵盤存在(或鍵盤逃生=後退按鈕)
相關問題