如何在Android的API 24之前的设备上设置锁屏墙纸?

问题描述 投票:5回答:1

我有一张图片,想要将其设置为锁屏墙纸。对于API 24及更高版本的设备,我们可以使用

wallpaperManager.setBitmap(bitmap,null,true,WallpaperManager.FLAG_LOCK)

但是我想在API 24之前的设备上执行此操作,就像许多其他壁纸应用程序一样。之前,此问题的答案为here,但它没有任何线索说明其他墙纸应用程序如何能够在API 24之前的设备上设置锁屏墙纸。还有其他解决方案建议该应用程序必须注册为媒体控制器才能进行临时替换,但这不是我的情况。请注意,我知道无法通过标准API实现这一事实,但是,我正在寻找一种替代方法。

android kotlin lockscreen wallpaper
1个回答
0
投票

使用此隐式意图在API 24之前的设备上设置墙纸或设置锁屏墙纸。

Intent intent = new Intent("android.intent.action.ATTACH_DATA");
intent.addCategory("android.intent.category.DEFAULT");
String str = "image/*";
intent.setDataAndType(Uri.fromFile(new File(your_file_url)), str);
intent.putExtra("mimeType", str);
startActivity(Intent.createChooser(intent, "Set As:"));
© www.soinside.com 2019 - 2024. All rights reserved.