Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 文件下载后,库项目未更新_Java_Android_Image Gallery_Android Gallery - Fatal编程技术网

Java 文件下载后,库项目未更新

Java 文件下载后,库项目未更新,java,android,image-gallery,android-gallery,Java,Android,Image Gallery,Android Gallery,我有一个壁纸应用程序,它有保存图像功能。其工作正常,但从应用程序下载的图像只有在重启手机后才会显示。有人能帮我解决这个问题吗? 我下载图片的代码如下所示 public类SaveTask扩展了AsyncTask { 私人语境; 私人对话; 字符串图像链接; URL myFileUrl; 字符串myFileUrl1; 位图bmImg=null; 文件; 公共保存任务(上下文){ this.context=上下文; } @凌驾 受保护的void onPreExecute(){ //TODO自动生成的

我有一个壁纸应用程序,它有保存图像功能。其工作正常,但从应用程序下载的图像只有在重启手机后才会显示。有人能帮我解决这个问题吗? 我下载图片的代码如下所示

public类SaveTask扩展了AsyncTask
{
私人语境;
私人对话;
字符串图像链接;
URL myFileUrl;
字符串myFileUrl1;
位图bmImg=null;
文件;
公共保存任务(上下文){
this.context=上下文;
}
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
pDialog=新建进度对话框(上下文);
setMessage(“下载图像…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…args){
//TODO自动生成的方法存根
试试{
myFileUrl=新URL(args[0]);
//myFileUrl1=args[0];
HttpURLConnection conn=(HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(真);
连接();
InputStream is=conn.getInputStream();
bmImg=BitmapFactory.decodeStream(is);
}
捕获(IOE异常)
{       
e、 printStackTrace();
}
试试{
String path=myFileUrl.getPath();
字符串idStr=path.substring(path.lastIndexOf('/')+1);
文件filepath=Environment.getExternalStorageDirectory();
File dir=新文件(filepath.getAbsolutePath()+“/Hindi Picture/”;
dir.mkdirs();
字符串文件名=idStr;
文件=新文件(目录,文件名);
FileOutputStream fos=新的FileOutputStream(文件);
bmImg.compress(CompressFormat.JPEG,75,fos);
sendBroadcast(新意图(Intent.ACTION\u MEDIA\u SCANNER\u SCAN\u文件,Uri.fromFile(新文件(idStr)));
fos.flush();
fos.close();
}
捕获(例外e)
{
e、 printStackTrace();
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串参数){
//TODO自动生成的方法存根
Toast.makeText(SlideImageActivity.this,“图像成功保存印地语图片文件夹/”,Toast.LENGTH_SHORT.show();
if(mInterstitial.isLoaded()){
mInterstitial.show();
}
pDialog.disclose();
}

}
您需要告诉系统运行媒体扫描仪,然后文件才会显示在多媒体资料中。可按如下方式进行:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
              Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

在您的onPostExecute中

MediaScannerConnection.scanFile(this,
          new String[] { filepath.getAbsolutePath() }, null,
          new MediaScannerConnection.OnScanCompletedListener() {
      public void onScanCompleted(String path, Uri uri) {
         // your code here
      }
 });