如何通过编程方式在Android中通过图片链接设置壁纸? [英] How to set a wallpaper through image link in android programmatically?

查看:87
本文介绍了如何通过编程方式在Android中通过图片链接设置壁纸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过图像链接设置为墙纸.

I am trying to set as wallpaper through image link.

我的问题:如何显示对话框从服务器加载图像"现在设置墙纸".出现此弹出窗口后,询问用户他们要设置的位置

My Question: How to show dialog box "loading Image from server" and now "Set wallpaper". After this Pop up appear to ask user where they want to set

当前情况:当用户点击设置墙纸"按钮时.它仅显示对话框消息并继续加载.然后用户需要关闭弹出窗口,然后再次单击.这意味着他们需要单击2次才能设置墙纸.我想让它们变得更加透明.

Current Situation: when user click the button "Set wallpaper". It only shows the dialog message and keep loading. then user need to dismiss the pop up and click again. Which means they need to click 2 times to set wallpaper. I want to make them easy to become more transparent.

基本上我希望我的用户知道android中正在运行哪个进程

Basically i want my user know which process is running in android

这是下面的代码

progressDialog = ProgressDialog.show(getActivity(),"Please wait...","Set as your wallpaper...",false,true);
               

                Picasso.get()
                        .load(setImgLink)
                        .into(new Target() {
                            @Override
                            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                                WallpaperManager wallpaperManager = WallpaperManager.getInstance(getActivity());

                                try {
                                    if (bitmap != null) {
                                        wallpaperManager.setBitmap(bitmap);
                                        Snackbar.make(relative_image_slider, "Wallpaper was set", Snackbar.LENGTH_SHORT).show();
                                        progressDialog.dismiss();
                                        ct_popup.setText("Wallpaper was set");
                                        final AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity());
                                        builder1.setView(subView);
                                        builder1.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.cancel();
                                                ((ViewGroup)subView.getParent()).removeView(subView);
                                            }
                                        });
                                        builder1.setIcon(R.mipmap.ic_launcher);
                                        builder1.setCancelable(false);
                                        builder1.create();
                                        builder1.show();
                                    }else {
                                        Toast.makeText(getActivity(), "Unable to set your wallpaper !!", Toast.LENGTH_LONG).show();
                                    }


                                } catch (IOException e) {
                                    Toast.makeText(getActivity(), "Something went wrong !!", Toast.LENGTH_LONG).show();
                                    e.printStackTrace();
                                }
                            }

                            @Override
                            public void onBitmapFailed(Exception e, Drawable errorDrawable) {

                            }

                            @Override
                            public void onPrepareLoad(Drawable placeHolderDrawable) {

                            }
                        });

推荐答案

嘿,我已经搜索了一些我找到的解决方案,请遵循

hey I have some search any i have found solution please follow

https://www.geeksforgeeks.org/how-to-set-an-image-as-wallpaper-programmatically-in-android/

​​以编程方式设置android手机的背景

这篇关于如何通过编程方式在Android中通过图片链接设置壁纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆