How can I get the package name of the current launcher in android 2.3 and above?
I think you should be able to use PackageManager.resolveActivity(), with the home intent.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String currentHomePackage = resolveInfo.activityInfo.packageName;
With the package visibility changes introduced in Android 11, it is now necessary to add a queries element in your application's manifest file as below before you can query the PackageManager.resolveActivity(intent:flags:) method for the default home (a.k.a. launcher) activity that is installed on the device as described in the accepted answer in this thread:
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent>
</queries>
If this queries element is omitted from your application's manifest, then the device will report the com.android.settings.FallbackHome
activity as its default home activity and that is most likely not what you want.