【发布时间】:2013-02-22 08:33:21
【问题描述】:
当没有 SD 卡时,我无法使用相机。
当有sdcard时,使用相机是微不足道的,例如
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。
有没有人在没有sdcard的情况下使用相机成功过?
【问题讨论】:
标签: java android camera sd-card