How to get default home application? - android

I want to get default home application name.For this i used
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.addCategory("android.intent.category.DEFAULT");
ResolveInfo resolveinfo =getApplicationContext().getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
defaultHomeName = resolveinfo.activityInfo.name;
This returns com.android.internal.app.ResolverActivity and when I tried following
List<RunningTaskInfo> runningTasks =((ActivityManager) getApplicationContext().getSystemService("activity")).getRunningTasks(1);
if (runningTasks != null && !runningTasks.isEmpty()) {
for (int i = 0; i < runningTasks.size(); i++) {
RunningTaskInfo runningtaskinfo = (RunningTaskInfo) runningTasks.get(i);
}
}
got home name as com.sec.android.app.twlauncher.Launcher inside this when on the home screen .
Why the same application shows different names?How to get a unique name for default home application for all devices?

Why the same application shows different names?
Because they are not the same application.
Specifically, com.android.internal.app.ResolverActivity is the resolver activity, what we tend to refer to as the activity chooser, or simply "chooser" for short. That comes up for resolveActivity() because there are two or more activities that can handle your chosen Intent.
How to get a unique name for default home application for all devices?
By using queryIntentActivities() on PackageManager, instead of resolveActivity(), you will get a list of all installed home screens. If this list has more than one entry on it, after filtering out your own home screen (should you be writing one), you have no reliable way necessarily of determining which of those is the "default home application".

Related

Android- How can I choose an app for a future intent, without executing that intent? [duplicate]

This question already has answers here:
Android. Custom Intent chooser
(3 answers)
Closed 6 years ago.
I would like to be able to have the ability for users to be able to set up a predefined email, which is stored and then sent later based upon some trigger. The stumbling block here is that I want the user to be able to choose what app they use for this. Simply calling Intent.createChooser does nothing on its own, the app is not selected until startActivity() is called on it, which then opens the selected app. The problem here is, since I want to send the email later, either the app chooser is not triggered until the email is (which may be while the screen is off), or the app chooser is triggered at setup-time, which will then leave my app, interrupting setup, when an app is selected in the chooser.
Is there some way to have a createChooser-style menu open, allowing the user to select one of the apps available for association with a certain intent, but then merely return the name of that app to my app, so that its information can be stored for creating and executing later intents?
You can do this:
PackageManager packageManager = getPackageManager();
List<String> results = new ArrayList<String>();
Intent intent = new Intent(YourAction); //Put any action string you have in mind
//Or any Intent intent = new Intent(...) you think fits
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : activities) {
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (activityInfo != null) {
results.add(activityInfo.name);
}
}
results will hold the activity names that can perform the action you need.

How to not show app chooser Android

I have an intent that dials a number as follows:
Intent intent = new Intent(isTelephonyEnabled() ? Intent.ACTION_CALL : Intent.ACTION_VIEW);
intent.setData(Uri.parse(number));
cordova.getActivity().startActivity(intent);
callbackContext.success();
The function isTelephoneEnabled() just makes sure that a Telephony Manager exists:
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
The issue is, an app chooser opens up and asks for instance if I want to dial using Skype or through the normal Phone app. How do I prevent the app chooser from opening up? I want it to go straight to the default option everytime (the normal phone).
I just give you an idea to do what you want.
You can get the list of all the activities that may receive your intent. Use PackageManager.queryIntentActivities for it. This method returns a list of ResolveInfo objects. And you may retrieve an Activity name out of ResolveInfo
Then you should choose one activity, that you want to open, and send your intent to this activity (use Intent.setComponent for instance).

Get the launcher activity name

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

When is a Home not a Home (Launcher related)

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.

How would I go about getting the package names of the applications that can be Home on android

My activity gets set as the default Home by the user, but I want to be able to launch the default Home from within my activity as well. I've tried hard coding the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
PackageManager pm = getPackageManager();
String packageName = "com.android.launcher";
String className = "com.android.launcher.Launcher";
final ComponentName cn = new ComponentName(packageName, >className);
intent.setComponent(cn);
This seems to work on my droid, but force closes on the HTC Ally. I'm thinking there's an easier way to just get a list of the apps that have the category Home and Default.
For those that have used the Home Swittcher app. I essentially want to generate that list of installed default Home activities on the phone.
Step #1: Create an Intent that launches whatever the user has for the default HOME application. In other words, do not try putting in the ComponentName.
Step #2: Call queryIntentActivities() on PackageManager to find out who all can respond to that Intent.
Step #3: If there are only two entries in the list, find out which is yours, and the other one is the platform's. If there are 3+ entries in the list, remove yours and let the user choose among the remaining options.
You could sorta combine #2 and #3 by using queryIntentActivityOptions() if you like, setting it up to filter your own Intent out of the list.

Categories

Resources