Reputation: 586
I currently have a button that, when pressed, the user gets asked to choose a camera app and allows him/her to take a picture.
Firstly, I want to get rid of the choice so that when the button is pressed the user is immediately in the camera interface. This is the code I'm using right now (after having tried many solutions online), which does prompt the user to choose a camera:
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
PackageManager pm = this.getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Intent intent = new Intent();
intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name));
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
} catch (Exception e) {
Log.i("TAG", "Unable to launch camera: " + e);
}
I have skimmed through a few articles that say it is not possible to launch the Android native/default camera without a chooser - however, I see apps like Facebook and WhatsApp that are able to do this so I'm sure it is possible.
As always I appreciate any help. Thanks in advance!
Upvotes: 1
Views: 1443
Reputation: 37
There are two ways to access the camera in Android- you can send an intent to an existing app, as you are doing here, or you can build a custom camera feature within your app. It is much easier to use existing apps, but as you have seen, the user must choose that app. Facebook and WhatsApp are probably using a custom camera feature. http://developer.android.com/guide/topics/media/camera.html#custom-camera
Upvotes: 1