1
當沒有SD卡時,我無法使用相機。
當有SD卡時,使用照相機是微不足道的,例如,
http://www.vogella.com/articles/AndroidCamera/article.html +大量的其他例子。但是,我需要讓我的應用可用於沒有SD卡的設備(例如Sony Xperia系列)。我嘗試修改代碼,以便使用內部存儲器(我認爲):
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(getDir("myDirec", Context.MODE_WORLD_WRITEABLE), "tmp_photo_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
file.createNewFile();
mImageCaptureUri = Uri.fromFile(file);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
intent.putExtra("return-data", true);
然而,當結果是:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intentReturn) {
if (resultCode != RESULT_OK)
return;
String path = mImageCaptureUri.getPath();
Bitmap bitmap = BitmapFactory.decodeFile(path);
...
bitmap
爲空。
這使我相信有一些權限問題....也許?
我試過一些其他的內部存儲選項,例如http://developer.android.com/guide/topics/data/data-storage.html#filesInternal,例如getFilesDir()
但結果相同:null bitmap
。
有沒有人在沒有SD卡的情況下使用相機有任何成功?
真棒,謝謝,工作。 – tomblah 2013-02-24 00:55:42