Eit*_*n F 2 android mediastore android-intent android-camera
我正在尝试使用MediaStore.ACTION_IMAGE_CAPTURE意图拍摄个人资料照片.
启动意图的代码:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File myPicture = new File(OfflineApp.getAppContext().getFilesDir() + "/" + getResources().getString(R.string.contact_photos_dir), getResources().getString(R.string.my_photo_file_name));
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(myPicture));
startActivityForResult(cameraIntent, REQUEST_CODE_TAKE_PHOTO);
Run Code Online (Sandbox Code Playgroud)
和onActivityResult部分:
case REQUEST_CODE_TAKE_PHOTO:
if (resultCode == RESULT_OK) {
String path = new File(OfflineApp.getAppContext().getFilesDir() + "/" + getResources().getString(R.string.contact_photos_dir), getResources().getString(R.string.my_photo_file_name)).getAbsolutePath();
ContactManager.getInstance().updateMyImage(path);
}
break;
Run Code Online (Sandbox Code Playgroud)
但是,结果代码总是RESULT_CANCELED在我提供的情况下MediaStore.EXTRA_OUTPUT,即使文件不存在也是如此.
好的.发现了问题.
由于Camera Intent正在启动Camera应用程序,因此无法访问我的apps文件夹.通过传递外部文件夹文件并将其复制到我的本地文件夹来修复它.
干杯.
| 归档时间: |
|
| 查看次数: |
1559 次 |
| 最近记录: |