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);
}
Related
i have some sort of a LauncherApp(start other apps easy from my app). On some devices i mentioned that the Camera is not in the PackageManager:
List<ApplicationInfo> appInfo = pm.getInstalledApplications(PackageManager.GET_META_DATA);
This is because on this Devices the Camera is not an Application, but an Activity in the Gallery-Application!
The Problem is that my whole logic is based on ApplicationInfos and not ActivityInfos!
I managed to get the ActivityInfo of the Camera via an intent:
Intent camera = new Intent(android.provider.MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
camera.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityInfo actInfoCamera = camera.resolveActivityInfo(getPackageManager(), 0);
now with actInfoCamera i can retrieve the icon of the camera and the Label. Which is all i need. But again my whole program is now based on ApplicationInfo. So i would need to cast or transform the ActivityInfo into an ApplicationInfo(For sorting, retrieving Icons and labels and so on).
When i try so with:
actInfoCamera.applicationInfo;
i am back at the beginning, the ApplicationInfo now has again the icon of the Gallery and the Label Gallery... or when i try that:
ApplicationInfo appInfoCamera = (ApplicationInfo) actInfoCamera;
it doesn't work cast from ActivityInfo to ApplicationInfo is not possible..
So i got two questions:
1) Is there a way to determine if the camera on that device is an single application or an activity within the Gallery application. Because i don't want to add two times the same camera application in my list in my app. Also please notice that it is possible that the user have some other camera apps which includes "camera" in their packagenames. I'm afraid it isn't that easy...
2) How do i get the activity of my camera within the gallery package as an ApplicationInfo to accomplish an easy way of implementing in my whole logic.
Any help is greatly appreciated.
Thanks in advance!
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"
Now i am working on a Home Launcher application.I want to clear defaults of default home launcher(eg: Samsung Home). ie.I want to show Settings-> Applications->Manage Application->Samsung Home->clear defaults programmatically.
How to show this through code?
Thanks in Advance
NOTE: Since this question is limited to accessing the Manage Application Settings options, my answer covers just that. You will have to figure out a way of getting the actual Package Name.
Also, if the idea is to also Clear the Defaults automatically via code, then that, to the best of my knowledge, cannot be done. Someone can correct me if I am wrong on this.
That being said, this piece of code will open the specific application's Manage Application screen from your app (the package name must be supplied).
Intent showSettings = new Intent();
showSettings.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uriAppSettings = Uri.fromParts("package", "THE_APP_PACKAGE_NAME", null);
showSettings.setData(uriAppSettings);
startActivity(showSettings);
For example, if the package name of the Google Maps application is com.google.android.apps.maps, the replace THE_APP_PACKAGE_NAME with it and the code will open the Manage Application screen for the Google Maps application.
UPDATE:
The PackageManager has a method, clearPackagePreferredActivities used to clear the default via code. However, that doesn't seem to work in newer Android versions: https://stackoverflow.com/a/10246711/450534
Other posts worth reading:
https://stackoverflow.com/a/7750187/450534
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/Rzv8VU-EUAw
Just for complete the picture, for getting "THE_APP_PACKAGE_NAME" youc can use something like that :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String packageName = resolveInfo.activityInfo.packageName;
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'm writing an app that uses the camera. I want to lauch an intent to allow users to annotate the resulting image with lines and text, AND I would like to provide the user with a list of appropriate image editting apps they can use, but I'm coming across these problems:
1. Not all image editting apps appear in the list when I perform this code:
editIntent = new Intent();
editIntent.setAction(Intent.ACTION_EDIT);
Uri imageToEditUri = selectedPhotoLocation; // Uri of existing photo
String imageToEditMimeType = "image/*";
editIntent.setDataAndType(imageToEditUri, imageToEditMimeType);
startActivityForResult(Intent.createChooser(editIntent,"Edit Image"), IMPLICIT_EDIT_IMAGE);
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
2. PS Express is the only app I've found that returns the Uri of the editted image in the data.getDate() Uri returned to OnActivityResult(), with other apps the user is forced to save, remember the location, and reselect the editted image.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
Not all image editting apps appear in the list when I perform this code
Just because an app implements image editing does not necessarily mean that it is set up to allow third parties to link to their image-editing activities.
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
If you mean that you want to do this programmatically at runtime, see Jedil's answer.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
No, except for those applications that have documentation on how developers should integrate with them.
First question answer:
try queryIntentActivities
Intent editIntent = new Intent(android.content.Intent.ACTION_EDIT);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(editIntent, 0);