2013-01-09 72 views
0

我使用这个代码从相机图片没有出现在画廊

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
File storagePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/Camera/"); 

if(!storagePath.isDirectory()){ 
    storagePath.mkdirs(); 
} 

File myImage = new File(storagePath, 
Long.toString(System.currentTimeMillis()) + ".jpg"); 
Uri fromURI=Uri.fromFile(myImage); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, fromURI); 
startActivityForResult(intent,PulseConstants.CAMERA_REQUEST_CODE); 

的图像与在手机的“我的文档”文件夹中指定的文件名正确存储拍照......但当我打开手机的图库时,此图像不会出现?

请让我知道如果我做错了什么?

TIA, VijayRaj

回答

0

这可能与事实Android的媒体扫描仪是不是经常在手机上的文件编制索引做。在过去,我已经叫下面的函数保存图像通知MediaScanner后:

private void scanMedia(File file) { 
    Uri uri = Uri.fromFile(file); 
    Intent scanFileIntent = new Intent(
     Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri); 
     sendBroadcast(scanFileIntent); 
} 

希望这个作品!