Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if my application is the default launcher [duplicate]

Tags:

I am developing a buissness-application that is essentially a Home-screen, and is supposed to be used as a Default Homescreen (being a "kiosk"-application).

Is there any way of checking if my Launcher is the default Launcher? Thanks!

Ps. Similar example, but for checking GPS-settings

LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {     Stuffs&Actions; } 
like image 983
DagW Avatar asked Nov 28 '11 17:11

DagW


People also ask

How do I know what my default launcher is?

How do I know what my default launcher is? With some Android phones you head to Settings > Home, and then you choose the launcher you want. With others you head to Settings > Apps and then hit the settings cog icon in the top corner where you'll then options to change default apps.

How do I find my first app launch Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken textview, when user open application, it will check whether it is the first time or not.


2 Answers

You can get list of preferred activities from PackageManager. Use getPreferredActivities() method.

boolean isMyLauncherDefault() {     final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);     filter.addCategory(Intent.CATEGORY_HOME);      List<IntentFilter> filters = new ArrayList<IntentFilter>();     filters.add(filter);      final String myPackageName = getPackageName();     List<ComponentName> activities = new ArrayList<ComponentName>();     final PackageManager packageManager = (PackageManager) getPackageManager();      // You can use name of your package here as third argument     packageManager.getPreferredActivities(filters, activities, null);      for (ComponentName activity : activities) {         if (myPackageName.equals(activity.getPackageName())) {             return true;         }     }     return false; } 
like image 176
Sergey Glotov Avatar answered Sep 30 '22 17:09

Sergey Glotov


boolean isHomeApp() {     final Intent intent = new Intent(Intent.ACTION_MAIN);     intent.addCategory(Intent.CATEGORY_HOME);     final ResolveInfo res = getPackageManager().resolveActivity(intent, 0);     if (res.activityInfo != null && getPackageName()             .equals(res.activityInfo.packageName)) {         return true;     }     return false; } 
like image 23
Oded Breiner Avatar answered Sep 30 '22 16:09

Oded Breiner