java - Gallery item is not updated After file downloading -


i have 1 wallpaper application have save image function. working fine image downloaded application showing after restart mobile. can 1 please me solve issue ? code download image below.

public class savetask extends asynctask<string , string , string>  			{  				  				    private context context;  				    private progressdialog pdialog;  				    string image_url;  				    url myfileurl;  				    string myfileurl1;  				    bitmap bmimg = null;  				    file file ;    				    public savetask(context context) {  				        this.context = context;  				    }    				    @override  				    protected void onpreexecute() {  				        // todo auto-generated method stub    				        super.onpreexecute();    				        pdialog = new progressdialog(context);  				        pdialog.setmessage("downloading image ...");  				        pdialog.setindeterminate(false);  				        pdialog.setcancelable(false);  				        pdialog.show();    				    }    				    @override  				    protected string doinbackground(string... args) {  				        // todo auto-generated method stub    				        try {      				            myfileurl = new url(args[0]);  				            //myfileurl1 = args[0];    				            httpurlconnection conn = (httpurlconnection) myfileurl.openconnection();     				            conn.setdoinput(true);     				            conn.connect();       				            inputstream = conn.getinputstream();  				            bmimg = bitmapfactory.decodestream(is);   				        }  				        catch (ioexception e)  				        {         				            e.printstacktrace();    				        }  				        try {           				            string path = myfileurl.getpath();  				            string idstr = path.substring(path.lastindexof('/') + 1);  				            file filepath = environment.getexternalstoragedirectory();  				            file dir = new file (filepath.getabsolutepath() + "/hindi picture/");  				            dir.mkdirs();  				            string filename = idstr;  				            file = new file(dir, filename);  				            fileoutputstream fos = new fileoutputstream(file);  				            bmimg.compress(compressformat.jpeg, 75, fos);  				            sendbroadcast(new intent(intent.action_media_scanner_scan_file, uri.fromfile(new file(idstr))));  				            fos.flush();      				            fos.close();  				                  				        }  				        catch (exception e)  				                {  				                    e.printstacktrace();    				                }  				        return null;     				    }      			    @override  			    protected void onpostexecute(string args) {  			        // todo auto-generated method stub  			    	toast.maketext(slideimageactivity.this, "image saved succesfully hindi picture folder/", toast.length_short).show();  			    	if (minterstitial.isloaded()) {  						minterstitial.show();  					}  			        pdialog.dismiss();  			    }  			}

you need tell system run media scanner , file appear in gallery. can done follows:

sendbroadcast(new intent(intent.action_media_mounted,               uri.parse("file://"+ environment.getexternalstoragedirectory()))); 

or

mediascannerconnection.scanfile(this,           new string[] { filepath.getabsolutepath() }, null,           new mediascannerconnection.onscancompletedlistener() {       public void onscancompleted(string path, uri uri) {          // code here       }  }); 

in onpostexecute


Comments