使用ACTION_SET_WALLPAPER设置壁纸 [英] set wallpaper using ACTION_SET_WALLPAPER

查看:1008
本文介绍了使用ACTION_SET_WALLPAPER设置壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的设置墙纸经理传递一个位图这个工程墙纸,但这个形象是静态的,所以它不会在屏幕上移动,并没有给我一个选项,以裁剪图像。我想用ACTION_SET_WALLPAPER在当我打电话的那一刻,它为保存图像,但是当它试图设置图像裁剪它,它给了我举杯未能加载图像,并退出回到我的应用程序,

我尝试

 位图位图=((BitmapDrawable)WallpaperView.getDrawable())getBitmap()。                    意图setAs =新意图(Intent.ACTION_ATTACH_DATA);
                    setAs.setType(图像/ JPG);
                    ByteArrayOutputStream字节=新
                    ByteArrayOutputStream();
                    bitmap.com preSS(Bitmap.Com pressFormat.JPEG,100字节);
                    文件f =新的文件
             (Environment.getExternalStorageDirectory()+文件分割符+
                /my_tmp_file.jpg);
                    尝试{
                        f.createNewFile();
                        FileOutputStream中FO =新的FileOutputStream(F);
                        fo.write(bytes.toByteArray());
                    }赶上(IOException异常五){
                        e.printStackTrace();
                    }
                    setAs.setDataAndType
      (Uri.parse(Environment.getExternalStorageDirectory()+文件分割符+
      /my_tmp_file.png\"),\"image/jpg);
                    setAs.putExtra(mime类型,图像/ JPG);
                    startActivity(Intent.createChooser(setAs,设置图片
                    如));

仍然浇在此我code保存图像,然后询问用户希望将图像作为什么,但随后与敬酒斜面负荷的形象崩溃的是,如果我去了文件管理器,我可以选择像我刚才保存并设置为壁纸没有问题,是有任何人谁可以告诉我为什么不起作用?

堆栈跟踪...

  java.lang.IllegalArgumentException异常:URI不是绝对的:/storage/emulated/0//my_tmp_file.png
        在java.net.URI.toURL(URI.java:1376)
        在com.lge.gallery.data.UriImage $ JobState.openOrDownloadInner(UriImage.java:147)
        在com.lge.gallery.data.UriImage $ JobState.openFileOrDownloadTempFile(UriImage.java:105)
        在com.lge.gallery.data.UriImage $ JobState。prepareInputFile(UriImage.java:198)
        在com.lge.gallery.data.UriImage $ BitmapJob.getBitmap(UriImage.java:256)
        在com.lge.gallery.data.UriImage $ BitmapJob.run(UriImage.java:249)
        在com.lge.gallery.data.UriImage $ BitmapJob.run(UriImage.java:240)
        在com.android.gallery3d.app.CropImage $ LoadBitmapDataTask.run(CropImage.java:1490)
        在com.android.gallery3d.app.CropImage $ LoadBitmapDataTask.run(CropImage.java:1483)
        在com.lge.gallery.util.ThreadPool $ Worker.run(ThreadPool.java:167)
        在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:587)
        在java.lang.Thread.run(Thread.java:818)
        在
 com.lge.gallery.util.PriorityThreadFactory $ 1.run
(PriorityThreadFactory.java:43)
07-23 00:47:26.395 26470-26470 /? I / StorageStateManager:
ROOTPATH​​ = /存储/模拟/ 0 / AVAILABLE_SIZE = 5782491136 request_size = 1500000
07-23 00:47:26.395 26470-26470 /? I / FloatableActivity:onPostResume
 活性= com.android.gallery3d.app.CropImage
(com.android.gallery3d.app.CropImage@149b6d72)
07-23 00:47:26.450 26470-26470 /? I / FloatableActivity:从附
窗口活性= com.android.gallery3d.app.CropImage
07-23 00:47:26.530 26470-27056 /? I / GalleryEGLConfigChooser:配置选择:
 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:布局内容窗格1440x2200
07-23 00:47:26.568一○五○年至1151年/? I / SystemUI [框架]:
PhoneWindowManager.updateSystemUiVisibilityLw():知名度= 0x8600,
PKG = com.android.gallery3d
07-23 00:47:26.569 1461年至1461年/? I / [SystemUI] NavigationThemeResource:通知
导航栏颜色(0xff000000)
07-23 00:47:26.570一○五○年至1151年/? W / PhoneWindowManagerEx:
呼叫!getLGSystemUiVisibility。 =为0x0
07-23 00:47:26.570一○五○年至1151年/? I / SystemUI [框架]:==> disabledNaviBtn()
什么=为0x0,token=android.os.Binder@64e735,PKG = WindowManager.LayoutParams
07-23 00:47:26.570一○五○年至1151年/? I / SystemUI [框架]:disableNaviBtn:
mDisabledNaviBtn =为0x0,mDisableRecords.size = 0
07-23 00:47:26.570 1461年至1461年/? I / [SystemUI] NavigationThemeResource:
NavigationKey颜色改变(WHITE_WITH_SHADOW - > WHITE)
BarMode = 4,主题=黑色,LightBackground = FALSE(非透明)


解决方案

在搜索的日子里,我管理这个使用这个家伙回答的这里

I'm currently setting the wallpaper using wallpaper manager passing it a bitmap this works but this image is static so it doesn't move with the screen and it doesn't give me an option to crop the image. I want to use the ACTION_SET_WALLPAPER at the moment when I call it, it works for saving the image but when it tries to set the image to crop it, it gives me a toast "failed to load image" and quits back to my application,

my attempt

 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"));

still pouring over this my code saves the image and then asks what the user would like to set the image as but then crashes still with the toast cant load image, if I go to the file manager I can select the image I have just saved and set it as the wallpaper no problem is there anyone who can tell me why this doesn't work?

stacktrace...

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$1.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)

解决方案

After days of searching I managed to solve this using this guys answer here

这篇关于使用ACTION_SET_WALLPAPER设置壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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