如何将图像发送到画廊来设置壁纸?发送到、画廊、如何将、图像

2023-09-06 08:58:24 作者:那些年少輕狂

我试图使用集成默认库的应用程序设置为墙纸的选择,我不知道如何使用意图的图像发送到画廊。我附上FB应用如何样的样子。

 字符串的root = Environment.getExternalStorageDirectory()的toString()。                    新的文件(根+/+ Constants1.APPNAME).mkdirs();                    文件fil​​eForImage =新的文件(根+/\"+Constants1.APPNAME,POS +.JPG);                    如果(fileForImage.exists())fileForImage.delete();                    尝试{                        FileOutputStream中出=新的FileOutputStream(fileForImage);                        arg0.com preSS(Bitmap.Com pressFormat.PNG,100,出);                        Toast.makeText(getApplicationContext(),图像保存到+ Constants1.APPNAME +文件夹,Toast.LENGTH_SHORT).show();                        了out.flush();                        out.close();                    }赶上(例外五){                        e.printStackTrace();                    }                    意图emailIntent =新意图(Intent.ACTION_ATTACH);                    emailIntent.setType(图像/ PNG);                    emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(fileForImage));                    startActivityForResult(Intent.createChooser(emailIntent,POS +。JPG),0); 

的问题是,图像不传递给像册..

解决方案

 意图emailIntent =新意图(Intent.ACTION_ATTACH_DATA);                        emailIntent.setDataAndType(Uri.fromFile(fileForImage),图像/ *);                        //emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(fileForImage));                        startActivity(emailIntent);                        Toast.makeText(getApplicationContext(),图像保存到+ Constants1.APPNAME +文件夹,Toast.LENGTH_SHORT).show(); 

适用于Ubuntu 18.04的4款最佳壁纸自动切换软件

i was trying to integrate set as wallpaper option using default gallery app, I don't know how to send the image to gallery using intent. I am attaching fb app samples how its look like.

 String root = Environment.getExternalStorageDirectory().toString();
                    new File(root + "/"+Constants1.APPNAME).mkdirs();


                    File fileForImage = new File(root + "/"+Constants1.APPNAME, pos  + ".jpg");
                    if (fileForImage.exists()) fileForImage.delete(); 
                    try {
                        FileOutputStream out = new FileOutputStream(fileForImage);
                        arg0.compress(Bitmap.CompressFormat.PNG, 100, out);
                        Toast.makeText(getApplicationContext(), "Image is saved to "+Constants1.APPNAME+" folder", Toast.LENGTH_SHORT).show();
                        out.flush();
                        out.close();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Intent emailIntent = new Intent(Intent.ACTION_ATTACH);
                    emailIntent.setType("image/png");
                    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileForImage));
                    startActivityForResult(Intent.createChooser(emailIntent, pos+".jpg"),0);

The problem is that the image is not passing to the gallery..

解决方案

     Intent emailIntent = new Intent(Intent.ACTION_ATTACH_DATA);
                        emailIntent.setDataAndType(Uri.fromFile(fileForImage), "image/*");
                        //emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileForImage));
                        startActivity(emailIntent);
                        Toast.makeText(getApplicationContext(), "Image is saved to "+Constants1.APPNAME+" folder", Toast.LENGTH_SHORT).show();