三星S3在onActivityResult相机意图数据空值(INT申请code,INT结果code,意图数据) [英] camera intent data null in onActivityResult(int requestCode, int resultCode, Intent data) in Samsung S3
问题描述
问题:我收到相机意图的数据空值在 onActivityResult(INT申请code,INT结果code,意图数据)
三星S3。但是,工作以及对其他一些设备。我定制了自己的$ C $下获取数据,并在网络搜索这个问题,但没有找到有用的。
code:
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == TAKE_CAMERA和放大器;&放大器;数据= NULL和放大器;!&安培;!data.getData()= NULL)
否则,如果(要求code == TAKE_CAMERA){
如果(结果code = RESULT_OK!)回报;
意向意图=新的意图(com.android.camera.action.CROP);
intent.setDataAndType(tempFileUri,图像/ *);
intent.putExtra(outputX,90);
intent.putExtra(outputY,90);
intent.putExtra(aspectX,1);
intent.putExtra(aspectY,1);
intent.putExtra(规模化,真正的);
intent.putExtra(回归数据,真正的);
startActivityForResult(意向,CROP_CAMERA);
}否则,如果(要求code == CROP_CAMERA和放大器;&安培;!数据= NULL){
。位图照片= data.getExtras()getParcelable(数据);
尝试 {
FileOutputStream中出=新的FileOutputStream(tempFileUri.getPath());
photo.com preSS(Bitmap.Com pressFormat.JPEG,90,出);
}赶上(FileNotFoundException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
如果(照片!= NULL){
imagePhoto.setImageBitmap(照片);
<我的code取代;
}
}
我面临同样的问题,得到了解决用下面的方式肯定会帮助你TR出来一次:
有关的解决方案,我提到以下链接解决这个问题:
<一个href="http://kevinpotgieter.word$p$pss.com/2011/03/30/null-intent-passed-back-on-samsung-galaxy-tab/"相对=nofollow>三星Galaxy S3 相机解决方案
编写下面code,而调用捕捉的图像:
意向意图=新的意图(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(意向,PICK_FROM_CAMERA);
,让你的URI通过下面的方式里面OnActivityResult()方法:
如果(结果code!= RESULT_OK)
返回;
开关(要求code){
案例PICK_FROM_CAMERA:
Log.i(TAG,内部PICK_FROM_CAMERA);
//描述列,你想回来了。从选择
//缩略图的位置让你俩的缩略图ID,如
//以及原始图象ID
尝试 {
Log.i(里三星手机,TAG,);
的String []投影= {
MediaStore.Images.Thumbnails._ID,//我们想要的列
MediaStore.Images.Thumbnails.IMAGE_ID,
MediaStore.Images.Thumbnails.KIND,
MediaStore.Images.Thumbnails.DATA};
串选择= MediaStore.Images.Thumbnails.KIND +=+ //选择
// 只要
// mini的
MediaStore.Images.Thumbnails.MINI_KIND;
字符串排序= MediaStore.Images.Thumbnails._ID +DESC;
//目前,这是一个黑客位,因为我全退
//图像,只是把最新的一个。有一种更好的方法
// 至
我觉得有一个WHERE子句,即//缩小下来
// 目前
//选择变量
光标myCursor = this.managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
投影,选择,空,排序);
长imageId =0升;
长thumbnailImageId =0升;
字符串thumbnailPath =;
尝试 {
myCursor.moveToFirst();
imageId = myCursor
.getLong(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID));
thumbnailImageId = myCursor
.getLong(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
thumbnailPath = myCursor
.getString(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
} 最后 {
// myCursor.close();
}
//创建新的光标,以获得较大的图像文件路径
的String [] largeFileProjection = {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA};
字符串largeFileSort = MediaStore.Images.ImageColumns._ID
+DESC;
myCursor = this.managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
largeFileProjection,NULL,NULL,largeFileSort);
字符串largeImagePath =;
尝试 {
myCursor.moveToFirst();
//这实际上给哟uthe文件路径的位置
// 图像。
largeImagePath = myCursor
.getString(myCursor
.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA));
mImageCaptureUri = Uri.fromFile(新文件(
largeImagePath));
} 最后 {
// myCursor.close();
}
//这是两个URI的你会感兴趣。他们给
//你
//处理实际图像
乌里uriLargeImage = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
将String.valueOf(imageId));
乌里uriThumbnailImage = Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
将String.valueOf(thumbnailImageId));
//我已经离开了剩下的code,因为我要做的就是分配
// URI的
//我自己的对象反正...
}赶上(例外五){
Log.i(TAG,
内抓三星手机异常+ e.toString());
}
尝试 {
Log.i(TAG,URI正常:+ mImageCaptureUri.getPath());
}赶上(例外五){
Log.i(TAG,Excfeption内的正常URI:+ e.toString());
}
// doCrop();
打破;
Problem: I am getting camera intent's data null in onActivityResult(int requestCode, int resultCode, Intent data)
in Samsung S3. But working well on some other devices. I customized my code for getting data and searched this issue in web but nothing found useful.
Code :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_CAMERA && data != null && data.getData() != null)
else if (requestCode == TAKE_CAMERA) {
if (resultCode != RESULT_OK) return;
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(tempFileUri, "image/*");
intent.putExtra("outputX", 90);
intent.putExtra("outputY", 90);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP_CAMERA);
} else if (requestCode == CROP_CAMERA && data != null) {
Bitmap photo = data.getExtras().getParcelable("data");
try {
FileOutputStream out = new FileOutputStream(tempFileUri.getPath());
photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (photo != null) {
imagePhoto.setImageBitmap(photo);
<my code>
}
}
I have Faced the Same Issue and got Work around with Below Way it will definitely help you tr it out once :
For the Solution i have referred below link for solve the issue :
Camera Solution for Samsung Galaxy S3
Write the Below Code While calling captured image :
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, PICK_FROM_CAMERA);
And Get your URI by Below way inside OnActivityResult() Method:
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case PICK_FROM_CAMERA:
Log.i("TAG", "Inside PICK_FROM_CAMERA");
// Describe the columns you'd like to have returned. Selecting from
// the Thumbnails location gives you both the Thumbnail Image ID, as
// well as the original image ID
try {
Log.i("TAG", "inside Samsung Phones");
String[] projection = {
MediaStore.Images.Thumbnails._ID, // The columns we want
MediaStore.Images.Thumbnails.IMAGE_ID,
MediaStore.Images.Thumbnails.KIND,
MediaStore.Images.Thumbnails.DATA };
String selection = MediaStore.Images.Thumbnails.KIND + "=" + // Select
// only
// mini's
MediaStore.Images.Thumbnails.MINI_KIND;
String sort = MediaStore.Images.Thumbnails._ID + " DESC";
// At the moment, this is a bit of a hack, as I'm returning ALL
// images, and just taking the latest one. There is a better way
// to
// narrow this down I think with a WHERE clause which is
// currently
// the selection variable
Cursor myCursor = this.managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, selection, null, sort);
long imageId = 0l;
long thumbnailImageId = 0l;
String thumbnailPath = "";
try {
myCursor.moveToFirst();
imageId = myCursor
.getLong(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID));
thumbnailImageId = myCursor
.getLong(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
thumbnailPath = myCursor
.getString(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
} finally {
// myCursor.close();
}
// Create new Cursor to obtain the file Path for the large image
String[] largeFileProjection = {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA };
String largeFileSort = MediaStore.Images.ImageColumns._ID
+ " DESC";
myCursor = this.managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
largeFileProjection, null, null, largeFileSort);
String largeImagePath = "";
try {
myCursor.moveToFirst();
// This will actually give yo uthe file path location of the
// image.
largeImagePath = myCursor
.getString(myCursor
.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA));
mImageCaptureUri = Uri.fromFile(new File(
largeImagePath));
} finally {
// myCursor.close();
}
// These are the two URI's you'll be interested in. They give
// you a
// handle to the actual images
Uri uriLargeImage = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
String.valueOf(imageId));
Uri uriThumbnailImage = Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
String.valueOf(thumbnailImageId));
// I've left out the remaining code, as all I do is assign the
// URI's
// to my own objects anyways...
} catch (Exception e) {
Log.i("TAG",
"inside catch Samsung Phones exception " + e.toString());
}
try {
Log.i("TAG", "URI Normal:" + mImageCaptureUri.getPath());
} catch (Exception e) {
Log.i("TAG", "Excfeption inside Normal URI :" + e.toString());
}
//doCrop();
break;
这篇关于三星S3在onActivityResult相机意图数据空值(INT申请code,INT结果code,意图数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!