Search code examples
androidbuildlive-wallpapervariantandroid-productflavors

Android Flavor ACTION_CHANGE_LIVE_WALLPAPER


Hi I'm trying to implement android app flavor (free and full) to live wallpaper. In eclipse, I used to use this following code to open live wallpaper preview from my own android Activity:

        Intent intent = new Intent();
        intent.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
        String pkg = WallpaperService.class.getPackage()
                .getName();
        String cls = WallpaperService.class.getCanonicalName();
        intent.putExtra(
                WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                new ComponentName(pkg, cls));

But now it does not work correctly as the free and full flavor are using same package name with just different applicationId in android studio. The problem is when it starts either in free or full version, it will goto full version no matter how, regardless of what flavor it is. I specify app flavor using applicationId in project gradle like this:

productFlavors {
    free {
        applicationId "com.kkl.app.free"
    }
    full {
        applicationId "com.kkl.app"
    }
}

How do we make it to get the correct package name that matches the app flavor?


Solution

  • You can call getPackageName() in your Activity to get Android packageName. This will be packageName from manifest file i.e. the one equal to current applicationId.

    Method documentation can be found here.