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