TouchWiz launcher detection

1.1k views Asked by At

I am currently working on a Live Wallpaper in Android. It turned out the Samsung's TouchWiz launcher never calls the onOffsetChanged method. The only way here is to detect if TouchWiz is running and to simulate the scrolling accordingly. Is there a way to detect if my Live Wallpaper is running under Samsung's TouchWiz launcher?

2

There are 2 answers

1
FriendlyAgent On BEST ANSWER

You can detect if a Launcher is Installed using the following code provided in the examples below;

First One

boolean isLauncherInstalled  () {
    final String myLauncherPackageName = "LAUNCHER PACKAGE NAME"; // com.sec.android.app.launcher

    final IntentFilter filterCategory = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filterCategory);

    List<ComponentName> activities = new ArrayList<ComponentName>();
    final PackageManager packageManager = (PackageManager) getPackageManager();

    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (myLauncherPackageName.equals(activity.getPackageName())) {
            return true; // Is a match so you have a Launcher installed. 
        }
    }
    return false; // No Launcher. 
}

Second One

public boolean isLauncherInstalled() {
    final String myLauncherPackageName = "LAUNCHER PACKAGE NAME"; // com.sec.android.app.launcher

    IntentFilter filterCategory = new IntentFilter(Intent.ACTION_MAIN);
    filterCategory.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filterCategory);

    List<ComponentName> preferredActivities = new ArrayList<ComponentName>();
    final PackageManager packageManager = (PackageManager) getPackageManager();

    packageManager.getPreferredActivities(filters, preferredActivities, myLauncherPackageName);

    if (preferredActivities != null && preferredActivities.size()> 0) {
        return true; // Is a match so you have a Launcher installed.
    }
    return false; // No Launcher. 
}

However your best option wil be to always simulate scrolling, because there are more Launchers that don't trigger OnOffsetsChanged. But when you actually get a call to OnOffsetsChanged just disable simulated scrolling. This way OnOffsetsChanged can function normally if it's available.

The following article will give you an idea of how to approach this; Artikel Link

0
Josh On

Don't try to detect the launcher, as HTC does this on some devices as well.

Better solution is to assume you WON'T get scroll events, and ALWAYS initially do your simulated scrolling. Then, if you get a call to onOffsetChanged (which will happen with most launchers), disable your simulated scrolling and carry on as normal.