2013年8月18日星期日

Results of the implementation of the Camera call android nocallback onActivityResult ()

I call android system camera:
Uri uri = Uri.fromFile (new File (imagepath));

Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);

intent.putExtra (MediaStore.EXTRA_OUTPUT, uri);

mactivity.startActivityForResult (intent, 2);

open system camera, and rewrite the onActivityResult (int requestCode, int resultCode, Intent data) method.
@ Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult (requestCode, resultCode, data);
if (requestCode == 2 && resultCode == RESULT_OK)
{
cameraview.iview.setImageURI (Uri.fromFile (new File (cameraview.imagepath)));

Bitmap bmp = (Bitmap) data.getExtras (). get ("data");
Log.d ("Test", "bmp width" + bmp.getWidth () + ", height:" + bmp. getHeight ());
}
}

my picture, click on the OK button, nothing happens. Click the Cancel button before onActivityResult callback method.

Please enlighten the great God, why click "OK" no callback onActivityResult method? ? ? ?

------ Solution ------------------------------------ --------
http://blog.csdn.net/shen332401890/article/details/9313379
reference

In addition, your application launchmode is what? Default What?

Also try upstairs first try without judgment conditions
------ For reference only --------------- ------------------------
wording right, you put && resultCode == RESULT_OK get rid of this judgment.
you what other phones on the same way?
------ For reference only -------------------------------------- -
I replied to the 1st and 2nd floor, next question.

About resultCode == RESULT_OK this judgment until after I was done together with comparative tests.
not resultCode == RESULT_OK before this condition, the result is the same.
key to select OK to ask when they did not enter the onActivityResult () this method will not even come resultCode == RESULT_OK this judgment.

Another launchmode should be the default, because I did not move on launchmode things.

Thank you.
------ For reference only -------------------------------------- -
you to download what I give you to connect the provided code to see results. That is what I debugged program! ! ~

There changer loom try your code
------ For reference only ------------------------ ---------------
good I try it.
------ For reference only -------------------------------------- -


guy after Reply electricity supplier references or else you do not see ah! ! ~! ~! ~
------ For reference only ------------------------------------- -


guy make sure you provide under this thing really. http://blog.csdn.net/shen332401890/article/details/9313379

I downloaded this project there is no code. Is empty. Really.
------ For reference only ---------------------------------------


sorry I was wrong. I try again.
------ For reference only ---------------------------------------
CSDN may be also a problem , download upload resources out there are problems previously encountered, such as time and then download it! ~
------ For reference only ---------------------------------------

I have seen That code. And there is not much, but I do not.

Intent takePictureIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra (MediaStore.EXTRA_OUTPUT, Uri.fromFile (f));

I just set putExtra () when the MediaStore.EXTRA_OUTPUT replaced MediaStore.EXTRA_SHOW_ACTION_ICONS, click on OK and the callback parameter can also correct.
But this is no way to save the image pathname.

mean that I'm using MediaStore.EXTRA_OUTPUT or not, choose to save the true way to post or old problem.
------ For reference only -------------------------------------- -
I suspect that you tune camera application in question, and then you try to install an additional camera applications try
------ For reference only -------- -------------------------------

I found a problem.
In onActivityResult (int requestCode, int resultCode, Intent data) this method.
If you click OK data value should be NULL click Cancel, data have value.
I putExtra () parameter to MediaStore.EXTRA_SHOW_ACTION_ICONS first time. Determine whether or cancel, although you can callback onActivityResult () method, but data values ​​have been worth it.
And when I changed the correct MediaStore.EXTRA_OUTPUT. Click OK to not be able to call back to onActivityResult () this method.
so I suspect in the internal callback onActivityResult () method, the parameters for which data has been set limits, there may be data is NULL, do not return to onActivityResult () method of this. This is just my guess.

CAMERA also say you have a problem what is meant? I call the system CAMERA, you're saying that this system CAMERA question is not it?
Or CAMERA version of this method or a problem?


Halo ah, this problem has troubled me for two days.
------ For reference only -------------------------------------- -
I am referring to here is the system Camera Camera app, you can try to install other Camera application is OK


------ For reference only ---------------------------------- -----
OK.
solved the problem.
finally found the problem is not the path to save the file.
I define a path String imagepath = "/ storage/sdcard0/text/touxiang.png";
While creating a file before it writes
if (! vFile.exists ()) {
File vDirPath = vFile.getParentFile ();
vDirPath.mkdirs ();
}
ensure the path is absolute existence, but in the new File (imagepath); to identify the path.
So then create or useless. Then I created the correct path.
Press the OK button on the call to onActivityResult (). And successfully saved.

1 条评论:

  1. Maybe that directory, or whole server requires password authentication?

    回复删除