start camera without asking for result - java

I am looking for an intent to start the camera application without asking for a result.
the only thing i found yet is Camera.ACTION_NEW_PICTURE but this only shoots a photo, I want to display the usual camera app, just without wanting a result from it!
Is there any way to do so?
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
this is basically the relevant code, as this app provides an extension for DashClock, which uses a service and this might be just a wrapper for a pending intent. However, this code causes to infinitely let the camera take pictures on pressing "shoot" and on accept or return button it crashes.

Yeah, try this one:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(cameraIntent);

Related

Is it possible to prompt a permission request from IME on Android without losing focus on the IME itself?

I'm working on an custom Keyboard that will need to access the micrphone for speech recognition. The system that actually uses speech recognition is already in place, but I wanted to prompt the user to give permission only at the moment they press the microphone button. The issue is that the code I'm used to use
if (ContextCompat.checkSelfPermission(...) == PackageManager.PERMISSION_DENIED) {
ActivityCompat.requestPermissions(activity, permissions, 0);
}
requires an activity, which I cannot access from an Input Method Service. I actually managed to make it work by creating a new activity and piping all the permissions requests there, but I'd like it to not hide the Keyboard when doing so. Here's how I start the new Activity:
Intent intent = new Intent(this, PermissionsActivity.class); //this being the Input Method Service
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(PermissionsActivity.PERMISSIONS_EXTRA, permissionsArray);
Is there another, better way to achieve this without creating an Activity or avoiding to hide the keyboard?
I've been catching the permission error and then launching a translucent activity to ask for the permission, something like this:
if (errorCode == SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS) {
Intent intent = new Intent(SpeechInputMethodService.this, PermissionsRequesterActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SpeechInputMethodService.this.startActivity(intent);
}
(See the full code in https://github.com/Kaljurand/K6nele/blob/6aa44a8b6df680f0f8355572ef0cc0bc7224bf00/app/src/main/java/ee/ioc/phon/android/speak/service/SpeechInputMethodService.java#L547-L551)
The keyboard is not hidden in this case. But maybe there is a better way.

Android Programming - Always Restarts same Intent

I am using Android Studio for a simple communication app and this definitly might be a stupid question but I couldn't find the answer to it yet.
I am simply starting a new intent on a button click. However, the very first time the user does this, he is asked what kind of app he wants to use. Therefore, there are at least two applications with the same intent filter, namely "ACTION_VIEW"
My Problem:
After the initial click the button always "reuses" his initial choice so the user does not have a decision anymore which app he wants to use for this intent.
Unfortunately, this is excactly what I want. The user should get the chance to select the app of his favor each time he clicks on the button.
The relevant part of code is as simple as follows:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
Intent.FLAG_UPDATE_CURRENT could probably help you.
https://developer.android.com/reference/android/app/PendingIntent.html
You can use an App Chooser to show the dialog for the user to choose which app to use each time:
[I]f the action to be performed could be handled by multiple apps and the user might prefer a different app each time—such as a "share" action, for which users might have several apps through which they might share an item—you should explicitly show a chooser dialog.... The chooser dialog forces the user to select which app to use for the action every time (the user cannot select a default app for the action).
Intent intent = new Intent(Intent.ACTION_SEND);
...
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show chooser
Intent chooser = Intent.createChooser(intent, title);
// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

Android: How to launch call intent using google voice?

How to launch specific intent (such as call) using google voice? How to pass phone number using intent? Following code launches google voice but what value to be passed for making call using google voice as intent extras?
final Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.apps.googlevoice", "com.google.android.apps.googlevoice.activity.conversationlist.ConversationListActivity"));
intent.putExtra("label", "<phone number>");
startActivity(intent);
Here what should i put in label to start the intent that launches a call using google voice?
Any help is appreciated... Thanks in Advance...
NEVER target applications directly like that UNLESS it is in your package. You should be using the Intent filter to catch that particular application. Sometimes you have to target an application like this, but this brings up the risk of change in package name errors.
To handle your particular application, you need to look at how information is being passed into Google voice. this will give you insight and how to target it WITHOUT targeting the exact package name.
What #JoxTraex said makes sense. However some clients need funny features like this, so we have no way but to implement this:
try {
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + mobile));
intent.setPackage("com.google.android.apps.googlevoice");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (ActivityNotFoundException anfe) {
GMHintManager.getInstance().showError(context, "Google Voice not installed");
}
Yes, you should try-catch ActivityNotFoundException.

Camera control inside an Android application

I am building an application for Android 2.2 which is based on a photo library. There is an option to take picture from camera and use it in the application. I am expecting:
To enable the camera from the application.
To take the picture.
To automatically close the camera and show the captured picture inside the application
Unfortunately, I am not able to get the captured image to the application. Once photo is taken, camera is not closing automatically or returning to the app. Now I have to click the back button to go to the app and select the picture manually select from SD card. Camera is opening through intent and I am using the following class.
http://developer.android.com/reference/android/hardware/Camera.html
You need to do two things. Start the Camera app and tell it where to store the picture that it takes:
File photo = new File(Environment.getExternalStorageDirectory(), "myFile.jpg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
startActivityForResult(intent, myRequestCode);
When the user closes the Camera app, you app and Activity will be resumed. So you must override onActivityResult to get the result:
if (resultCode == myRequestCode){
File photo = new File(Environment.getExternalStorageDirectory(), "myFile.jpg");
// open it, show it, insert into MediaStore whatever
}
If you don't provide the place to save, you can alternatively retrieve it using either intent.getData or intent.getParcelableExtra using Intent.EXTRA_STREAM.
I guess .. you are doing similar to the below code
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// request code
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
using startActivityForResult instead of startActivity.. whenever you are done with your camera.. press ok.. and you will come back to your activity.. then in your activity onActivityResult callback will be called. here you will get the data for the clicked image.
Thanks.

Debugging Intents

I asked a question previously about what shows up in the IntentChooser when I send an Intent with ACTION_SEND and MIME type "image/png". The problem is that some phones come with a default messaging app that is not showing up in the list, mine included (myTouch 4G) as well as a user that I speak with over email (using an HTC EVO). If I choose a Send or Share option from the built in gallery app or another application on the same image I'm saving and attempting to send directly from my app, Messages shows up in the list. From my app it does not. Other phones don't have this problem, so it's clearly a platform specific thing. But that doesn't mean I should just ignore the problem.
So, I go to troubleshooting the issue. I register one of the activities in my app to receive the the same type of intent, and then hit a breakpoint to analyze the Intent object being sent from the two different ways of sending it.
The problem is, the intent I'm sending and the intent being sent from Gallery or AndroZip (where Messages does show up in the chooser) seem to be the same. They both have the same action, same categories, same flags, same mime type. What else can I inspect on the Intent from Gallery or AndroZip to tell if there's some more information I can add to my Intent to get the default messaging app to show up in the chooser in cases where it is not?
The problem is specific to HTC Sense phones, and it arises because their Gallery and Messaging apps are different to the stock ones.
Specifically the Intent sent from Gallery to Messaging has the action android.intent.action.SEND_MSG which is different to android.intent.action.SEND. The Sense messaging app doesn't handle SEND, unlike the stock messaging app.
So the question becomes, how is the Sense Gallery app creating an activity chooser dialog which combines both SEND and SEND_MSG ?
I've done some research and got mostway there... the code below works, but the "Messages" entry in the dialog appears at the top rather than in alphabetical order as per Gallery. Doubtless some more research into intents would correct that, but at least this works:
// Create a chooser for things that can ACTION_SEND images
Intent intent = new Intent(Intent.ACTION_SEND);
Uri data = Uri.parse("content://media/external/images/media/98");
intent.putExtra(Intent.EXTRA_STREAM, data);
intent.setType("image/jpeg");
Intent chooser = Intent.createChooser(intent, "Blah");
// Add the stupid HTC-Sense-specific secondary intent
Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.putExtra(Intent.EXTRA_STREAM, data);
htcIntent.setType("image/jpeg");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
// Show the chooser
startActivity(chooser);
First of all, +1 to Reuben, he is the genius, not me. But I had to modify his code a bit to get it to work. Basically I had to putExtra() on the htcIntent or the image never got stuck to the Intent.
Tested and validated on a Droid X and HTC Incredible (which had the same problem until now thanks to Reuben).
Uri uri = Uri.fromFile(new File(mFile));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.setType("image/png");
htcIntent.putExtra(Intent.EXTRA_STREAM, uri);
Intent chooser = Intent.createChooser(intent, "Send Method");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
startActivity(chooser);
Edit: I realize I'm putting the image on two Intents now, but I couldn't get it to work any other way.
Instead of debugging the intents, why not try to compare how your starting the chooser with how the gallery is doing it. It is open source after all, so instead of trying to guess at the issue with the result, you can debug from the cause.
https://android.googlesource.com/platform/packages/apps/Gallery3D

Categories

Resources