我想在我的Android应用中将图片设置为壁纸,有我的代码:
private class SetAsBackground implements View.OnClickListener {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Looper.prepare();
try {
mShareBitmap = Glide.with(WallPaperDetails.this).load(mImageURL).asBitmap()
.into(-1, -1).get();
} catch (final ExecutionException | InterruptedException e) {
Log.e("loading_fail", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void dummy) {
if (null != mShareBitmap) {
new ImageSaver(WallPaperDetails.this)
.setFileName("wallpaper.png")
.setDirectoryName("fine")
.save(mShareBitmap);
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(WallPaperDetails.this);
try {
Bitmap bitmap = new ImageSaver(WallPaperDetails.this)
.setFileName("wallpaper.png")
.setDirectoryName("fine").load();
myWallpaperManager.setBitmap(bitmap);
Toast.makeText(WallPaperDetails.this,
"Wallpaper successfully changed", Toast.LENGTH_SHORT)
.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.execute();
}
}
但我想这样做:
我怎样才能做到这一点 ?现在我使用带有图像保护程序类的壁纸管理器(我可以共享图像保护程序类的代码)。在谷歌搜索时,我没有找到任何其他答案。如果您可以解释该应用程序如何做到这一点,或分享一些代码......
答案 0 :(得分:0)
Public void xyz(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 0);
}