三星意图OnActivityResult未来空当通话摄像头 [英] Samsung Intent For OnActivityResult coming Null when call camera
问题描述
我使用下面的code来从摄像机画面。除了三星它工作正常在其他手机。请让我知道我做错了。
最后文件根=新的文件(Environment.getExternalStorageDirectory()+文件分割符+温度+文件分割符);
root.mkdir();
最后弦乐FNAME =IMG_+ System.currentTimeMillis的()+.JPG;
最终文件sdImageMainDirectory =新的文件(根,FNAME);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// 相机。
最后的名单,其中,意图> cameraIntents =新的ArrayList<意图>();
最终意图captureIntent =新的意图(MediaStore.ACTION_IMAGE_CAPTURE);
。最终PackageManager packageManager = cordova.getActivity()getPackageManager();
最后的名单,其中,ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent,0);
对于(ResolveInfo RES:listCam){
最后弦乐的packageName = res.activityInfo.packageName;
最终意向意图=新的意图(captureIntent);
intent.setComponent(新的组件名(res.activityInfo.packageName,res.activityInfo.name));
intent.setPackage(的packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri);
cameraIntents.add(意向);
}
//文件系统
最终意图galleryIntent =新意图();
galleryIntent.setType(为image / jpeg);
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
//的文件系统选项选择器。
最终意图chooserIntent = Intent.createChooser(galleryIntent,选择图像源);
//添加摄像头的选项。
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,cameraIntents.toArray(新Parcelable [] {}));
startActivityForResult(chooserIntent,PICK_FILE_REQUEST);
和onActivityResult
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == PICK_FILE_REQUEST){
如果(数据!= NULL){
Logv(数据,得到了一些数据);
}
}
}
除了三星是做工精细的其他移动
没有,这是唯一的工作与你已经尝试了设备的摄像头应用程序。它一般不会对 ACTION_IMAGE_CAPTURE
工作
请让我知道我做错了
正在假定 ACTION_IMAGE_CAPTURE
应该返回结果意图
。 当你提供不要求 EXTRA_OUTPUT
。你知道你问的图像保存(您所提供给 EXTRA_OUTPUT
,所以去看看那里的形象。值
请注意,有一些越野车的相机应用程序,将忽略 EXTRA_OUTPUT
(存储在那里他们想要的图像),因此,如果您的 ACTION_IMAGE_CAPTURE图像
请求不 EXTRA_OUTPUT
,你的运气了。
I am using following code to get picture from camera. Except samsung it is working fine in other mobiles. please let me know what i am doing wrong.
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);
And onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_FILE_REQUEST) {
if(data!=null){
Logv("Data","got some data");
}
}
}
Except samsung it is working fine in other mobiles
No, it is only working with the camera apps on the devices that you have tried. It generally will not work for ACTION_IMAGE_CAPTURE
.
please let me know what i am doing wrong
You are assuming that ACTION_IMAGE_CAPTURE
is supposed to return a result Intent
. It is not required when you provide EXTRA_OUTPUT
. You know where you asked for the image to be saved (the value you supplied to EXTRA_OUTPUT
, so go look there for the image.
Note that there are some buggy camera apps that will ignore EXTRA_OUTPUT
(storing the image where they want), so if the image from your ACTION_IMAGE_CAPTURE
request is not in EXTRA_OUTPUT
, you are out of luck.
这篇关于三星意图OnActivityResult未来空当通话摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!