我正在使用以下代码从相机获取图片。除三星外,其他手机均运行良好。请让我知道我做错了什么。
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "temp" + File.separator);
root.mkdir();
final String fname = "img_" + System.currentTimeMillis() + ".jpg";
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = cordova.getActivity().getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam){
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
//FileSystem
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/jpeg");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Image Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
startActivityForResult(chooserIntent, PICK_FILE_REQUEST);
和 onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_FILE_REQUEST) {
if(data!=null){
Logv("Data","got some data");
}
}
}
除三星外,其他手机均运行良好
不,它仅适用于您尝试过的设备上的相机应用程序。它通常不适用于ACTION_IMAGE_CAPTURE
.
请让我知道我做错了什么
你假设ACTION_IMAGE_CAPTURE
应该返回一个结果Intent
. 当您提供时,不需要EXTRA_OUTPUT http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE。您知道您要求将图像保存在哪里(您提供给EXTRA_OUTPUT
,所以去那里寻找图像。
请注意,有一些有缺陷的相机应用程序会忽略EXTRA_OUTPUT
(将图像存储在他们想要的位置),所以如果来自您的图像ACTION_IMAGE_CAPTURE
请求不在EXTRA_OUTPUT
,你运气不好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)