How to open default camera in your application?
I don't want to open chooser for it (its client's requirement). I am using this intent android.media.action.IMAGE_CAPTURE and calling activity for result.
Everything is fine but apps like Line Camera, Paper Camera are appearing in chooser with default camera app, i don't want to show chooser for.
Your attentions will be highly appreciated.
List<ApplicationInfo> list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
for (int n=0;n<list.size();n++) {
if((list.get(n).flags & ApplicationInfo.FLAG_SYSTEM)==1)
{
Log.d("TAG", "Installed Applications : " + list.get(n).loadLabel(packageManager).toString());
Log.d("TAG", "package name : " + list.get(n).packageName);
if(list.get(n).loadLabel(packageManager).toString().equalsIgnoreCase("Camera")) {
defaultCameraPackage = list.get(n).packageName;
break;
}
}
}
I find following solution and its working perfectly.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.setPackage(defaultCameraPackage);
startActivityForResult(takePictureIntent, actionCode);
you can filter default camera by setting package in above intent. I've tested it by installing two application Line Camera and Paper Camera both apps were showing chooser but filtering by package above code open only default camera.
The only easy you can pick a specific activity is by using explicit intents. And for the built in camera app the package name could be different and device dependent
I believe you can find your answer(and code) in the link below:
How to launch android camera using intents
The author states there specifically that:
"the code above should start the default Camera activity on your phone"
Related
I want to take a photo with the camera app which is default on the device. After taking it I have my own preview on which the user can input a text and accept the picture or refuse it. This already works fine.
My problem is now that some user has activated the preview option in the default camera app. Is there a parameter for the Intent to deactivate the default setting and send the picture directly to my app without a preview? I don't find a documentation for this case...
I start the camera with the following code
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
this.startActivityForResult(takePictureIntent, MY_CAMERA_REQUEST_CODE);
}
The alternative is to create a own camera in my app. But this is in my opinion a little bit oversized.
Thanks in advance for any help.
There is no possibility to disable the preview programmatically. If something different is needed as the settings of the default camera, an own camera has to be implemented :-(
I've written an app before where I open the native camera app to capture an image like this:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Or, like this for capturing video:
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
But is there a way to open the native camera app with the option to capture either video or an image? I'd like to open to the image given below, where the user can swipe to access the side-menu and change their input type.
I've tried searching, but no results have come up yet. I'm not sure if there is a way to do this without writing a custom camera implementation, which I'd like to avoid for now.
If this is possible, how can I do it? And how could I go about recognizing what media type the user has chosen once the capture is complete (in onActivityResult, probably)?
Thank you in advance!
Currently As specified by you there are 2 intents for capturing image and video i.e. MediaStore.ACTION_IMAGE_CAPTURE & MediaStore.ACTION_VIDEO_CAPTURElink.
For intially I was also thinking startActivityForResult (Intent intent, int requestCode, Bundle options), Here options param was used to give the extras for the external applications but we can only specify some animations not the values as specified link1 & link2.
Solution
I would rather suggest you to go for the custom app with options as you like rather than the restrictions given by the existing camera app.
I am building an app that auto sorts installed apps and allows the user to launch those apps. I just ran into a small issue with the camera app. When I scan through the installed apps with 'queryIntentActivities' for 'ResolveInfo' I get the gallery ResolveInfo twice and both objects are identical. I am wondering if I am missing something obvious or the camera is simply not launch-able from a package name.
If the camera and the gallery share the same package would I still be able to use the package manager to pull the icons and labels for each? I want to avoid using my own drawable as different OEMs make different icons.
I am aware that I can simply launch the camera with a capture image intent but I do not care for the results and I want to launch the camera as a stand alone activity plus using this intent doesn't really solve my issue.
Update:
So the ResolveInfo's I am receiving for the camera and gallery aren't exactly the same. They share the same package name but I can pull their respective icons through the ResolveInfo.loadLabel and ResolveInfo.loadIcon (rather then what I was doing with ResolveInfo.ApplicationInfo.loadLabel ... which returned identical labels and icons). However I am still unable to find any way to launch the activities for the camera and gallery separately.
Update 2.0
Problem solved. I found the unique activity string in the ResolveInfo.ActivityInfo.name. Now rather then launching the app with the package name I just launch it with the activity that was listed in that variable.
No, the package manager for camera and gallery are different.
for camera - com.android.camera.
for gallery - com.android.gallery.
this is the way in which you would differentiate the gallery and camera.
The best way to get the package name of the camera app is pasted below. You can get the package name by refering to cameraInfo.activityInfo.packageName; returned by the function below
public static ResolveInfo getCameraPackageName(Context context, PackageManager pm) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
ResolveInfo cameraInfo = null;
List<ResolveInfo> pkgList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(pkgList != null && pkgList.size() > 0) {
cameraInfo = pkgList.get(0);
}
return(cameraInfo);
}
I am trying to launch the gallery from my app when user clicks on the notification. I have found that it is only possible if you know the package and the class name of the Gallery app. I have managed to find the same for four device manufacturers, and so far this code works.
I just need the package and class name for Motorola and LG Android phones.
Can anyone help? It is very easy for you if you are a developer and own a Motorola or LG Android device. You just need to launch gallery in your phone while connected to LogCat, and it will show the package and class name of the Gallery.
CODE:
Intent newIntent = new Intent();
//open Gallery in Nexus plus All Google based ROMs
if(doesPackageExist("com.google.android.gallery3d"))
newIntent.setClassName("com.google.android.gallery3d", "com.android.gallery3d.app.Gallery");
//open Gallery in Sony Xperia android devices
if(doesPackageExist("com.android.gallery3d"))
newIntent.setClassName("com.android.gallery3d", "com.android.gallery3d.app.Gallery");
//open gallery in HTC Sense android phones
if(doesPackageExist("com.htc.album"))
newIntent.setClassName("com.htc.album", "com.htc.album.AlbumMain.ActivityMainCarousel");
//open gallery in Samsung TouchWiz based ROMs
if(doesPackageExist("com.cooliris.media"))
newIntent.setClassName("com.cooliris.media", "com.cooliris.media.Gallery");
startActivity(newIntent);
And to check if package name exists:
public boolean doesPackageExist(String targetPackage) {
PackageManager pm = getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(targetPackage, PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
return false;
}
return true;
}
You should be able to start the Gallery app via a basic Intent like this:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivity(intent);
It may fire the app picker if more than one app is able to let you display images (e.g. Gallery and ESFileExplorer).
There is no universal table describing the "Gallery" app on every Android device, so the best you can do to avoid showing the user the activity resolver is to list all of the possible activity handlers programmatically and make an informed guess about which one to launch.
PackageManager.queryIntentActivities turns an Intent into such a list of packages as long as you seed the Intent with the type of file to open:
Intent newIntent = new Intent(Intent.ACTION_VIEW);
newIntent.setType("image/*");
List<ResolveInfo> allHandlers = pm.queryIntentActivities(newIntent, PackageManager.MATCH_DEFAULT_ONLY);
You could then trawl this list for known packages (from your list above) or, failing that, launch the first one in the list.
However, you should consider making a trivial Activity of your own to display the image. That is the only way to gain the level of control you seek.
I am working on an app in which i have to click a pic a pic and save it to a specified folder. I am using android.provider.MediaStore.ACTION_IMAGE_CAPTURE in intent to invoke the camera .I am done with coding and my activity is working fine.But now i have a question in my mind that whether i should stick with this code or i should use the code given here.Need your precious suggestions on this topic.
Thanx in advance.
If you want to just click a picture and save it to a specified folder nothing more then You can use Intent and call ACTION_IMAGE_CAPTURE, it easy to let handle on camera activity do your stuff,
And If your application has some serious deep work with camera when you want to modify preview screen size, and all those things,(For this you have to handle all things like to manage camera, and when to release it, check for don't freeze main UI..) then you have to go with the code you suggested...
Choice is yours.....
I suggest you use the code from your link.
Because most of the stock camera apps don't work as expected with Image Capture. For example the Galaxy S2 and most other Samsung and HTC phones give you the picture bytes back and also save the picture in the standard DCIM Folder on SD-Card, if you want it or not.
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
this what u r searching i am thinking..