0

我的應用程序使用手機相機拍照並將它們保存在特定文件夾中。我無法看到他們與Android畫廊或插入到我的電腦,但我可以使用文件管理器應用程序。 我找到了一個解決方案:我用文件管理器應用程序重命名圖片,我可以在圖庫中看到它們。看不到保存在特定文件夾中的圖片

我正在使用的代碼是:

Intent camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
String dirName = Environment.getExternalStorageDirectory()+"/MyAPP/APP"+ n +".jpg"; 
Uri uriSavedImage = Uri.fromFile(new File(dirName)); 
camera.putExtra(MediaStore.EXTRA_OUTPUT,uriSavedImage); 
startActivityForResult(camera, 1); 
n++; 

AndroidManifest:

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

<uses-feature 
    android:name="android.hardware.camera" 
    android:required="false" /> 
+0

您可以打印目錄名稱變量和比較它到你用文件管理器看的路徑? –

+0

是的,它是一樣的。它可以節省他們,但有些奇怪的事情發生 – Goblinch

+0

嘗試使用「/ mnt/sdcard」而不是Environment.getExternalStorageDirectory(), –

回答

0

我只是需要加入一些代碼來掃描圖片,並將其添加到庫中

private void addGallery() { 
    Intent mediaScanIntent = new Intent(
      Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); 
    String currentPath = Environment.getExternalStorageDirectory() 
      + "/MyAPP/APP" + n + ".jpg"; 
    File f = new File(currentPath); 
    Uri contentUri = Uri.fromFile(f); 
    mediaScanIntent.setData(contentUri); 
    this.sendBroadcast(mediaScanIntent); 
} 

我補充它在onActivityResult和它的作品

0

用於保存圖像特定的文件夾,

private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) { 

File direct = new File(Environment.getExternalStorageDirectory() + "/DirName"); 

if (!direct.exists()) { 
    File wallpaperDirectory = new File("/sdcard/DirName/"); 
    wallpaperDirectory.mkdirs(); 
    } 

    File file = new File(new File("/sdcard/DirName/"), fileName); 
    if (file.exists()) 
     file.delete(); 
    try { 
     FileOutputStream out = new FileOutputStream(file); 
     imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out); 
     out.flush(); 
     out.close(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

}

嘗試一下本作訪問該圖像

private void showImage(String imageName) { 

    File direct = new File(Environment.getExternalStorageDirectory() + "/SlamImages"); 

    if (direct.exists()) { 

     File f = new File(Environment.getExternalStorageDirectory() + "/SlamImages/" + imageName); 

     if (f.exists() && !imageName.equals("")) { 
      Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath()); 
      imgUserLogo.setImageBitmap(bmp); 
     } else { 
      imgUserLogo.setImageResource(R.drawable.friend_image); 
      Toast.makeText(FriendsDetailsActivity.this, "Image Does not exist", Toast.LENGTH_SHORT).show(); 
     } 

    } 

} 
+0

我有同樣的問題 – Goblinch

+0

請給logcat – mdDroid

+0

Logcat不給出錯誤 – Goblinch

相關問題