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

How to set lock screen wallpaper on devices prior to API 24 in Android?

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

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

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

使用此隐式意图在 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:"));