gpt4 book ai didi

Android 风格 ACTION_CHANGE_LIVE_WALLPAPER

转载 作者:行者123 更新时间:2023-11-29 20:16:25 31 4
gpt4 key购买 nike

您好,我正在尝试将 Android 应用风格(免费且完整)实现为动态壁纸。在 Eclipse 中,我曾经使用以下代码从我自己的 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));

但现在它无法正常工作,因为免费版和完整版在 android studio 中使用相同的包名称,只是不同的 applicationId。问题是当它以免费版或完整版启动时,无论如何都会转到完整版,无论它是什么风格。我在项目 gradle 中使用 applicationId 指定应用风格,如下所示:

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

我们如何才能获得与应用风格匹配的正确包名称?

最佳答案

您可以在Activity 中调用getPackageName() 来获取Android packageName。这将是 list 文件中的 packageName,即等于当前 applicationId 的那个。

可以找到方法文档here .

关于Android 风格 ACTION_CHANGE_LIVE_WALLPAPER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33806740/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com