使用 ACTION_SET_WALLPAPER 设置墙纸

set wallpaper using ACTION_SET_WALLPAPER

我目前正在使用墙纸管理器设置墙纸,并向其传递一个位图,这可行,但该图像是静态的,因此它不会随屏幕移动,也没有给我裁剪图像的选项。我想在调用它的那一刻使用 ACTION_SET_WALLPAPER,它用于保存图像,但是当它尝试设置图像以裁剪它时,它给我敬酒 "failed to load image" 并返回到我的申请,

我的尝试

 Bitmap bitmap = ((BitmapDrawable) WallpaperView.getDrawable()).getBitmap();

                    Intent setAs = new Intent (Intent.ACTION_ATTACH_DATA);
                    setAs.setType("image/jpg");
                    ByteArrayOutputStream bytes = new      
                    ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG,100,bytes);
                    File f = new File 
             (Environment.getExternalStorageDirectory()+ File.separator +   
                "/my_tmp_file.jpg");
                    try{
                        f.createNewFile();
                        FileOutputStream fo = new FileOutputStream(f);
                        fo.write(bytes.toByteArray());
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                    setAs.setDataAndType
      (Uri.parse(Environment.getExternalStorageDirectory()+ File.separator +  
      "/my_tmp_file.png"),"image/jpg");
                    setAs.putExtra("mimeType", "image/jpg");
                    startActivity(Intent.createChooser(setAs, "Set Image 
                    As"));

我的代码仍然倾注于此,我的代码保存了图像,然后询问用户想要将图像设置为什么,但随后仍然崩溃,toast 无法加载图像,如果我转到文件管理器,我可以 select 我刚刚保存的图像并将其设置为墙纸 没问题 有人可以告诉我为什么这不起作用吗?

堆栈跟踪...

java.lang.IllegalArgumentException: URI is not absolute: /storage/emulated/0//my_tmp_file.png
        at java.net.URI.toURL(URI.java:1376)
        at com.lge.gallery.data.UriImage$JobState.openOrDownloadInner(UriImage.java:147)
        at com.lge.gallery.data.UriImage$JobState.openFileOrDownloadTempFile(UriImage.java:105)
        at com.lge.gallery.data.UriImage$JobState.prepareInputFile(UriImage.java:198)
        at com.lge.gallery.data.UriImage$BitmapJob.getBitmap(UriImage.java:256)
        at com.lge.gallery.data.UriImage$BitmapJob.run(UriImage.java:249)
        at com.lge.gallery.data.UriImage$BitmapJob.run(UriImage.java:240)
        at com.android.gallery3d.app.CropImage$LoadBitmapDataTask.run(CropImage.java:1490)
        at com.android.gallery3d.app.CropImage$LoadBitmapDataTask.run(CropImage.java:1483)
        at com.lge.gallery.util.ThreadPool$Worker.run(ThreadPool.java:167)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
        at 
 com.lge.gallery.util.PriorityThreadFactory.run
(PriorityThreadFactory.java:43)
07-23 00:47:26.395  26470-26470/? I/StorageStateManager﹕     
rootPath=/storage/emulated/0/ available_size=5782491136 request_size=1500000
07-23 00:47:26.395  26470-26470/? I/FloatableActivity﹕ onPostResume  
 activity=com.android.gallery3d.app.CropImage
(com.android.gallery3d.app.CropImage@149b6d72)
07-23 00:47:26.450  26470-26470/? I/FloatableActivity﹕ on attached from   
window activity=com.android.gallery3d.app.CropImage
07-23 00:47:26.530  26470-27056/? I/GalleryEGLConfigChooser﹕ Config chosen:   
 R8 G8 B8 A0 D0 S8 ID12 CAVEAT12344
07-23 00:47:26.540  26470-27056/? I/GLRootView﹕ onSurfaceChanged: 1440x2200,   
gl10: com.google.android.gles_jni.GLImpl@18efc101
07-23 00:47:26.541  26470-27056/? I/GLRootView﹕ layout content pane 1440x2200
07-23 00:47:26.568    1050-1151/? I/SystemUI[Framework]﹕   
PhoneWindowManager.updateSystemUiVisibilityLw() :visibility=0x8600,   
pkg=com.android.gallery3d
07-23 00:47:26.569    1461-1461/? I/[SystemUI]NavigationThemeResource﹕ notify   
navigation bar color(0xff000000)
07-23 00:47:26.570    1050-1151/? W/PhoneWindowManagerEx﹕   
Call!!!getLGSystemUiVisibility. =0x0
07-23 00:47:26.570    1050-1151/? I/SystemUI[Framework]﹕ ==>disabledNaviBtn()   
what=0x0, token=android.os.Binder@64e735,  pkg=WindowManager.LayoutParams 
07-23 00:47:26.570    1050-1151/? I/SystemUI[Framework]﹕ disableNaviBtn:   
mDisabledNaviBtn=0x0,  mDisableRecords.size=0
07-23 00:47:26.570    1461-1461/? I/[SystemUI]NavigationThemeResource﹕   
NavigationKey Color is changed(WHITE_WITH_SHADOW -> WHITE)
BarMode=4, Theme=BLACK, LightBackground=false (NOT Transparent)

经过几天的搜索,我设法使用这些人的回答解决了这个问题 here