2015年7月28日星期二

下载的图片保存到本地并立即生成问题

1.在网上下下来的图片保存到本地时并不会马上生成那个图片文件,
为了解决这个问题 可以使用
MediaStore.Images.Media.insertImage(context.getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());

但是这个方法只会保存到 安卓的存放照片的地址 也就是Camera


所以为了解决这个问题 使用下面的
 // Tell the media scanner about the new file so that it is
    // immediately available to the user.
    MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    Log.i("ExternalStorage", "Scanned " + path + ":");
                    Log.i("ExternalStorage", "-> uri=" + uri);
                }
    });

还可以使用 一下方法来 通知系统 重新扫描拍照文件
Intent localIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, camerafileUri);sendBroadcast(localIntent);

没有评论:

发表评论