I have a question this time around regarding the Android custom camera, NOT the built in camera that is accessible through Camera_intent. I am not permitted to use that one. What I am attempting to do is allow a user to aim the camera at something and choose "Send" on the onOptionsItemMenu.
I am not having any issues getting this implemented...separately. If I ask it to send something with the click of a button, it sends. If I tell the camera to save the picture without sending it, it does.
I run into a problem when I try to do both. As it stands, using this code:
public boolean onOptionsItemSelected(MenuItem item) {
Intent i;
File file2;
camera.takePicture(null, mPictureCallback, mPictureCallback);
switch (item.getItemId()) {
case R.id.save:
return super.onOptionsItemSelected(item);
case R.id.send:
file2 = new File(filename);
i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, "Sample Picture");
System.out.println("file//" + file2);
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file//" + file2));
i.setType("image/png");
startActivity(Intent.createChooser(i, "Email file"));
finish();
return super.onOptionsItemSelected(item);
The camera "clicks" or "flickers" as if it is taking the picture and then it immediately opens the mail client choose. When I select which I want to take Gmail is saying that the location is null. However if I remove the part that starts the email chooser, the image saves properly and is there.
Almost as if it is skipping over that camera taking step.
Im sure the solution to this is simple, I just have a baked brain right now and probably can't see the forest because of the trees. (if that is even how that analogy is said).
Do I run the camera part on another thread?
An idea I had was to use a boolean to check for the file's existence and size, but I am unsure how to make the program check that over and over again until it returns true.
I'm guessing what might be happening is that your callback is occurring on a separate thread. So, your "open mail client" action is occurring while your image is still being saved. What you should try, is have a flag of some sort that tells you if you are doing a send or save. Set this in the onOptionsItemSelected before you open the camera.. Then, in your mPictureCallback have that perform your ACTION_SEND intent (or save action)