Question

How to show a particular home screen in Android from the Android app. For example on pressing the home button on my app, I would like to show a particular home screen. As there can be multiple home screens, would like to insist the OS to show particular home screen.

And also how to get the number of home screens configured from android app?

Please let me know if anyone has the idea of the same.

Thanks.

Was it helpful?

Solution

since home screen is nothing but another app installed with an activity declared in manifest with the android:name="android.intent.category.HOME" attribute, to get list of all home screens - all you have to do is query packgage manager to get list of all packages having this attribute:

Intent intent = new Intent(Intent.ACTION_HOME, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List pkgHomeAppsList = getPackageManager().queryIntentActivities(intent , 0);

you can get it size of - course with pkgHomeAppsList.count();

in addition, you can pick each one of package from the list, and launch it like this:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageInfo.packageName)); 
launchIntent.addFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launchIntent);

For example on pressing the home button on my app, I would like to show a particular home screen

you can't control which home screen will launch when the user press the home button. only the user, by choosing what of the options available to him in the intent chooser. unless you run your app on rooted devices..

I would say that it was somehow possible launching the activity as I showed in reaction to home button click, but this event cannot be intercepted from apps that don't have system signature, so you can forget about that also.

even if you managed somehow to do that - I must warn you thew that launching home screen app like this is a very bad approach. you don't suppose to take this ability from the user unless you got really good reason (for example - if your app designed to work in ciosk mode for specific company or something like that.. )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top