I am developing an application my requirement is to finish my custom launcher and switch to default launcher. How can I achieve that?
follow the following steps:
By using Package Manager get the intents which is having launcher and category home. By using queryIntents method.
Use the 0th indexed intent and get the class name and package name. store some where else like sharedPreferences.
whenever you want to launch the default launcher just create intent with class name and packager name.
Then start that activity when it is required.
Following code may help you:
PackageManager packageManager = getPackageManager();
Intent i = new Intent();
i.addCategory(Intent.CATEGORY_HOME);
i.setAction(Intent.ACTION_MAIN);
List<ResolveInfo> queryIntentActivities = packageManager
.queryIntentActivities(i, 0);
ResolveInfo resolveInfo = queryIntentActivities.get(0);
String packageName = resolveInfo.resolvePackageName;
String className = resolveInfo.activityInfo.targetActivity;
Related
Is there any way to launch for one mobile app to launch another mobile app, e.g. via a button click?
Example: the org.apache.cordova.camera plugin allows direct access to the camera on a button click. In the same way, how can one app launch another app?
You can use this java code:
Intent LaunchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage("appPackage");
this.cordova.getActivity().startActivity(LaunchIntent);
or try any of these 2 plugins for launching apps:
https://github.com/lampaa/com.lampa.startapp
https://github.com/dmedvinsky/cordova-startapp
Try this
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("package name here");
startActivity( LaunchIntent );
If you don't know the package name of application that you want to launch then try this
PackageManager pm;
pm = getPackageManager();
// get a list of all installed apps then launch by pakagename.
packages = pm.getInstalledApplications(0);
String packagename = packages.get(position).packageName.toString()
Refer this android-package-manager
You need to find out full name of application, and then start it as activity via intent like this:
Intent myIntent = new Intent(getApplicationContext(), "full name of activity you are starting");
startActivity(myIntent);
You can even receive result from that activity check this. Hope this helps!
Hello i wan't to keep home activity name for launch it from my app.
I know we can launch the launcher without know is package name but.
I'm making a custom home and i will set it as default so this will launch my custom home.
I wan't to keep the launcher activity name on a shared preference the first time i launch my custom home and then i will be able to go on the default home from my personal home(without delete my home preference i will keep it as default and launch default home just for some debug test)
Don't know if i'm clear; i have difficult to understood myself in this subject so for resume
I need at the first launch of my activity get the name of the default launcher(because it's not com.android.launcher for every device) and keep it to be able to launch it after some time
Any idea?
Finaly i don't keep the name i don't care of it i just use the following code to launch a launcher who is not mine :P
PackageManager pm = getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
if (lst != null)
{
for (ResolveInfo resolveInfo : lst) {
if (resolveInfo.activityInfo.packageName != getPackageName()){
Intent res = new Intent();
String mPackage = resolveInfo.activityInfo.packageName;
String mClass = resolveInfo.activityInfo.name;
res.setComponent(new ComponentName(mPackage,mClass));
startActivity(res);
}
}
}
you can get application registered with intent action android.intent.category.HOME, and you can get package list for aplication registered with this intent.
May be this can also help
I am running into a very strange situation whereby I am getting a list of all the installed packages that have a CATEGORY_HOME intent.
My intention is to manually launch the native Home application (which is currently NOT the Default native Home application, because my application has that role).
So, the method I'm using (beneath) correctly identifies that there are two apps that are set up as CATEGORY_HOME.
When I try to launch the one that is mine (fetching the Launcher activity) it works fine. However, when I try to fetch the Launcher activity for the default one, it comes back as null.
So... I'm stumped. How do I determine what I should actually be launching when the package name of the stock home app returns null when I try and pull the relevant Launch activity via getLaunchIntentForPackag from it?
Here's what I'm doing (with some comments to avoid confusion), and for the record I know that not all of them will have the expression "android" in the name space, but I'm trying to get this to work initially on a device that does come back with that string so that part of it isn't the issue.
//get a list of all apps that set themselves up as CATEGORY_HOME
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
final List<ResolveInfo> list = ((PackageManager)getPackageManager()).queryIntentActivities(intent, 0);
String packageName = null;
//look for the one that has the word android in the package name
for(ResolveInfo ri : list){
if(ri.activityInfo.packageName.indexOf("android") != -1)
//this does get set correctly and looks like "com.sec.android.app.launcher"
packageName = ri.activityInfo.packageName;
}
PackageManager pm = SlidePlayer.this
.getPackageManager();
Intent it = pm.getLaunchIntentForPackage(packageName);
//it is NULL so this doesn't work
startActivity(it);
***EDIT
Trying out the following methodology based on CommonsWare's advice...
String packageName = null;
String className = null;
for(ResolveInfo ri : list){
//L.d("HOME PACK = " + ri.);
if(ri.activityInfo.packageName.indexOf("android") != -1){
className = ri.activityInfo.applicationInfo.className;
packageName = ri.activityInfo.applicationInfo.packageName;
}
}
//PackageManager pm = SlidePlayer.this
//.getPackageManager();
Intent it = new Intent();//pm.getLaunchIntentForPackage(packageName);
//both packageName and className appear to be set correctly
//packageName = "com.sec.android.app.launcher"
//className = "com.android.launcher2.LauncherApplication"
it.setClassName(packageName, className);
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);
EDIT 2*
semi huzzah...
On one device (Samsung Note II) the key is to set it via Component like so...
Intent it = new Intent();//pm.getLaunchIntentForPackage(packageName);
ComponentName cn = new ComponentName(packageName, className);
it.setComponent(cn);
//it.setClassName(packageName, className);
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);
This doesn't work on the Samsung Tab 10" or the Motorola M (which are the only other 2 devices I have thus far tested with this methodology).
getLaucnIntentForPackage looks specifically for CATEGORY_INFO or CATEGORY_LAUNCHER - not CATEGORY_HOME, in which case it will return null. From the Documentation:
public abstract Intent getLaunchIntentForPackage (String packageName)
Added in API level 3 Return a "good" intent to launch a front-door
activity in a package, for use for example to implement an "open"
button when browsing through packages. The current implementation will
look first for a main activity in the category CATEGORY_INFO, next for
a main activity in the category CATEGORY_LAUNCHER, or return null if
neither are found.
However, when I try to fetch the Launcher activity for the default one, it comes back as null.
That's because most firmware home screens are not designed to be launched by home screens, and so probably do not include a launcher activity.
How do I determine what I should actually be launching when the package name of the stock home app returns null when I try and pull the relevant Launch activity via getLaunchIntentForPackag from it?
Since it is a home screen, you know that it must have an activity with the same ACTION_MAIN/CATEGORY_HOME as you do. Find that one and start it.
I have a single widget that call another application, here is the most important part of the code:
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.android.settings",
"com.android.settings.wifi.WifiSettings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity( intent);
The important part is
final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
This call the wifi settings in android, but I found this code in a web site, I want to know how I can call the data roaming and other settings in the system, where I can see this?
com.android.settings is the name of the package. If you go here you can find all the settings available in this package. The roaming settings are in package com.android.phone - see here.
EDIT : it appears that using package names is not portable. Your best bet is to use :
startActivity(new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS));
The list of intents is in the Settings class
You may also need to add FLAG_ACTIVITY_NEW_TASK to your intent
hi Its been 2 days looking for this simple problem. I want to launch Android own launcher from my application EVEN if its not set as default.
final PackageManager packageManager=getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage("com.android.launcher");
this return null for Android own launcher but if I try custom launcher is give me successfully
Found the solution, after investigating source code of getLaunchIntentForPackage. As per documentation,
The current implementation will look first for a main activity in the
category CATEGORY_INFO, next for a main activity in the category
CATEGORY_LAUNCHER, or return null if neither are found.
So, the function don't look for CATEGORY_HOME, i rewrote it in following way, it worked perfectly.
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_HOME);
intentToResolve.setPackage("com.android.launcher");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null)
{
Intent intent = new Intent(intentToResolve);
intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
}
Are you sure the default Google Android Launcher being installed on your device? If not, then it's truly NULL.