从相机意图拍摄照片后,我在从“onActivityResult”方法获取数据时遇到问题。
这是我调用相机意图的方法:
private void __initCamera() {
String path = Environment.getExternalStorageDirectory() + "/vault/images/";
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
dir = new File(path);
}
String[] content = dir.list();
String fileName = (content.length + 1) + ".jpg";
File file = new File(path, fileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException ex) {
Log.e("my_app", ex.getMessage());
}
}
Uri uri = Uri.fromFile(file);
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(i, 8765);
}
这是我的 onActivityResult 方法:
返回码:-1(should be: 1, right?),
例外:java.io.FileNotFoundException: No content provider: #Intent;action=inline-data;end
data.toURI() :#Intent;action=inline-data;end
@Override
protected void onActivityResult(int requestCode, int returnCode, Intent data) {
try {
Bitmap bitmap = Media.getBitmap(getContentResolver(), Uri.parse(data.toURI()));
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
bitmap.recycle();
out.close();
} catch (Exception ex) {
Log.e("TROLL", ex.toString());
}
}