当前位置: 首页 > news >正文

安卓A15系统实现修改锁屏界面默认壁纸功能

最近遇到一个A15系统项目,客户要求修改锁屏界面的默认壁纸,客户提供了一张壁纸图片,但是从A15系统的源代码查看时才知道谷歌已经去掉了相关的代码,已经不支持了,A13和A14系统好像是支持的,A15系统的WallpaperManager.java有明显不支持的提示如下:

 所以必须采用其他的方法来实现,具体修改如下:

 1.将客户给的锁屏壁纸图片拷贝到源代码中,然后添加一行拷贝代码将图片拷贝到system/media/目录下即可,如下:

2. 到packages/apps/Settings/src/com/android/settings/SettingsInitialize.java这个类文件中去修改代码,为什么选择在这个文件去修改呢?是因为这个SettingsInitialize.java文件是机器第一次开机进系统时会执行一次,以后的重启或者开机都不会执行了,就不用去添加系统属性标记位去判断是否是第一次开机进系统,具体修改如下:

 

diff --git a/src/com/android/settings/SettingsInitialize.java b/src/com/android/settings/SettingsInitialize.java
index 4887e26940c..0b04660c95b 100644
--- a/src/com/android/settings/SettingsInitialize.java
+++ b/src/com/android/settings/SettingsInitialize.java
@@ -46,6 +46,16 @@ import com.android.settingslib.utils.ThreadUtils;import java.util.ArrayList;import java.util.List;+import android.app.WallpaperManager;
+import android.graphics.Bitmap;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import android.os.Handler;
+import android.content.Context;
+import android.graphics.BitmapFactory;
+import java.io.IOException;
+
+/*** Listens to {@link Intent.ACTION_PRE_BOOT_COMPLETED} and {@link Intent.ACTION_USER_INITIALIZE}* performs setup steps for a managed profile (disables the launcher icon of the Settings app,
@@ -58,6 +68,7 @@ public class SettingsInitialize extends BroadcastReceiver {private static final String PRIMARY_PROFILE_SETTING ="com.android.settings.PRIMARY_PROFILE_CONTROLLED";private static final String WEBVIEW_IMPLEMENTATION_ACTIVITY = ".WebViewImplementation";
+    private Context mContext;@Overridepublic void onReceive(Context context, Intent broadcast) {
@@ -69,8 +80,41 @@ public class SettingsInitialize extends BroadcastReceiver {webviewSettingSetup(context, pm, userInfo);ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context));enableTwoPaneDeepLinkActivityIfNecessary(pm, context);
+
+        mContext = context;
+        mLockScreenHandler.removeCallbacks(mLockScreenRunnable);
+        mLockScreenHandler.postDelayed(mLockScreenRunnable,1);}+    private Runnable mLockScreenRunnable = new Runnable() {
+        @Override
+        public void run() {
+           setLockScreenWallpaper();
+        }
+    };
+
+    private Handler mLockScreenHandler = new Handler();
+
+    private void setLockScreenWallpaper() {
+        WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
+        int FLAG_SET_LOCK = 1 << 1;
+        try {
+            //InputStream inputStream = new InputStream(new File("system/media/default_lock_wallpaper.png"));
+            //Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
+            Bitmap bitmap = BitmapFactory.decodeFile("system/media/default_lock_wallpaper.png");
+            //bitmap.eraseColor(0xFFBB86FC); //设置成紫色,有对应图片的话可以设置成对应图片
+            ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
+            if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, tmpOut)) {
+                byte[] outByteArray = tmpOut.toByteArray();
+                wallpaperManager.setStream(new ByteArrayInputStream(outByteArray), null,
+                                true, FLAG_SET_LOCK);
+            }
+        } catch (IOException e) {
+
+		}
+		
+     }
+private void managedProfileSetup(Context context, final PackageManager pm, Intent broadcast,UserInfo userInfo) {if (userInfo == null || !userInfo.isManagedProfile()) {

http://www.xdnf.cn/news/464401.html

相关文章:

  • 多个docker-compose-xx 停止并完全卸载 删除
  • C++:字符数组与字符串指针变量的大小
  • 鸿蒙OSUniApp制作多选框与单选框组件#三方框架 #Uniapp
  • 协作赋能-1-制造业生产流程重构
  • Midjourney 最佳创作思路与实战技巧深度解析【附提示词与学习资料包下载】
  • 一些问题杂记
  • NY244NY249美光闪存颗粒NY252NY256
  • unity terrain 在生成草,树,石头等地形障碍的时候,无法触发碰撞导致人物穿过模型
  • 全链路压测实战指南:从理论到高可用架构的终极验证
  • Transformer的理解
  • Elasticsearch 分片机制高频面试题(含参考答案)
  • 【备忘踩坑】Android单元测试中读取测试assets的方法
  • 一套基于 Bootstrap 和 .NET Blazor 的开源企业级组件库
  • C#中Action的用法
  • Milvus Docker 部署教程
  • 【FFmpeg+SDL】使用FFmpeg捕获屏幕,SDL显示
  • 套路化编程:C# winform ListView 自定义排序
  • 5款AI驱动的MySQL数据库管理工具:提升运维效率的智能之选
  • 数智化招标采购系统如何实现分散评标?
  • Git/GitLab日常使用的命令指南来了!
  • Python——文件、异常、模块与包
  • 深入理解浏览器中的 window、document 和 window.parent
  • HarmonyOs开发之———UIAbility进阶
  • NVIDIA Omniverse 现已支持中文!
  • 问题处理——在ROS2(humble)+Gazebo+rqt下,无法显示仿真无人机的相机图像
  • 【LLIE专题】基于码本先验与生成式归一化流的低光照图像增强新方法
  • 【JS】vue3中组件命名问题
  • 世界模型+大模型+自动驾驶 论文小汇总
  • 测试--BUG(软件测试⽣命周期 bug的⽣命周期 与开发产⽣争执怎么办)
  • 深入解析CountDownLatch的设计原理与实现机制