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;
Related
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 trying to figure out the intent values to open a specific application settings screen on Android, the one that allows you to "Clear Data", "Force Stop", "Uninstall"...
Thanks,
Adam.
CommonsWare have answered the question. Here is code you can copy/paste directly and use:
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
Use ACTION_APPLICATION_DETAILS_SETTINGS, with a Uri of package:the.app.goes.moo (replacing the package name with the one you want).
Note that this is new to API Level 9, and it might not work on every device.
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);
I would like to start a default application: browser, contact-book, phone, email, music app, etc. I have found many q/a, like browser opening a specific URL or blank, and here the answer is even "No not possible". But I would like to just open/launch it without telling it to go to a specific URL or sending a mail to someone, etc.
However, I also saw some Home applications where this seems to be working (at least for some apps). On my colleague's device there is for example a different contact-book (no google) which is detected and opened correctly.
I have seen in the Android documentation some intent categories that point to these problems, but these are only >= API.11. So I can't use/test them on my device.
Question: Is it not somehow possible to launch a default application (having the app chooser is of course ok) without providing extra data? If no, what do you think are these Home apps doing (perhaps workarounds are somehow possible).
PS: for the phone app I think, I have a workaround using Intent.ACTION_DIAL without any other information which will open simply the dialer.
UPDATE: I modified the title. Some applications like the address book may not be the same on different devices. So in this case I would like to start the address-book app, whichever this is.
This answer is not a 100% answer, but some workarounds on some typical applications.
Still open are: music player, address book
Browser: I get a list of applications that handle "http"-data intents, and then I look if one is available in the list of preferred applications.
Intent appFilter = new Intent(Intent.ACTION_VIEW);
appFilter.setData(Uri.parse("http://www.google.com"));
List<ResolveInfo> browserInfoList = pm.queryIntentActivities(appFilter, 0);
List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
List<ComponentName> outActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(outFilters, outActivities, null);
if(outActivities.size() > 0) {
for(ComponentName cn : outActivities) {
String cnClass = cn.getClassName();
String cnPkg = cn.getPackageName();
for (ResolveInfo info : browserInfoList) {
if(info.activityInfo.name.equals(cnClass) &&
info.activityInfo.packageName.equals(cnPkg)) {
return cn;
}
}
}
}
In case no default is found, I open a browser chooser dialog, see here.
Phone: as described in the question:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
You can start apps by the function "startActivity" if you know about the canonical app name
like "android.com.browser". Do this simple by searching for AndroidManifest.xml in the app
source code (look at Codeaurora.com or at github/Cyanogenmod) and grab the app name you want.
After you know about the App name ("Activity") implement the code as follows:
Intent intent = new Intent();
intent.setClassName(this, "com.android.browser");
intent.setCategory(Intent.ACTION_MAIN);
startActivity(intent);
THIS is only a example, sometimes you have to put intent extras or data values, this information can be found in the app's AndroidManifest.xml too.
I want to check if my application is set as the default application for the Intents I'm handling inside my App.
As an example ff more than one application supports to open a specified file format. I need to make my application as a default application from my code. How it possible to make my application a default (from the code)? Can anyone help me?
At least I would like to check this on startup of my app and redirect the user to fill in some information if my App is not set as the default on the device.
As far as I know this is not possible. That dialogue is handled by the system - your app will only be launched if the user picks your app from the list.
Allowing such a behaviour would impact the user's ability to control their default applications, and from a technical point of view would mean a process and its memory would have to be allocated to every app in the list every time such a list appeared.
You could use this method:
public static boolean isOurAppDefault(Context context) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);
String defaultBrowserPkg = null;
if (resolveInfo != null) {
if (resolveInfo.activityInfo != null) {
defaultBrowserPkg = resolveInfo.activityInfo.packageName;
}
}
return TextUtils.equals(context.getPackageName(), defaultBrowserPkg);
}
It's actual for some editor or browser. In other case use different Uri data for intent.