我对如何在颤振中将图像设置为墙纸感到困惑,我尝试在此处使用以下参考代码!
我的颤振代码:在这段代码中,我尝试从 URL 创建文件
//get URL image and save it and create a file
_setWallp(String imageUrl) async {
try {
var httpClient = http.Client();
var list = await httpClient.readBytes(imageUrl);
final tempDir = await getTemporaryDirectory();
final file = await new Io.File('${tempDir.path}/image.jpg').create();
file.writeAsBytes(list);
final channel = const MethodChannel('setwallpaper');
channel.invokeMethod('shareFile', 'image.jpg');
} catch (e) {
print('Share Error :$e');
}
}
Run Code Online (Sandbox Code Playgroud)
我的java代码:在这个java代码中,我尝试将位图设置为我在flutter中创建的文件路径中的墙纸
//call method channel from flutter
private static final String SHARE_CHANNEL = "setwallpaper";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this); …
Run Code Online (Sandbox Code Playgroud) 我是颤振的新手我想知道如何从颤振中的缓存图像网络获取路径,或者如何将网络图像保存到资产图像并获取该图像的路径?