2016-08-01 4 views
0

지정된 경로의 디렉토리에서 모든 이미지를로드하려고합니다. if 문을 사용하여 호출 된 경로를 확인하면 오류가 발생하지 않으며 결과도 표시되지 않습니다. 내가이 코드를 어디서 잘못 읽었는지 알 수는 없을 것이다.디렉토리에서 이미지 읽기

public class Edit extends Activity { 

    // File representing the folder that you select using a FileChooser 
    static final File dir = new File("/data/data/faceemoji.alexcz.yourfaceemoji/app_imageDir/"); 

    // array of supported extensions (use a List if you prefer) 
    static final String[] EXTENSIONS = new String[]{ 
      "png" // and other formats you need 
    }; 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_edit); 

     LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linearlayout); 

     Log.d("loadfilepath", dir.getAbsolutePath()); 
     if (dir.isDirectory()) { // make sure it's a directory 
      System.out.println("yes"); 
      for (File f : dir.listFiles(IMAGE_FILTER)) { 

       Log.d("fak", "file found"); 
       Bitmap myBitmap = BitmapFactory.decodeFile(f.getAbsolutePath()); 
       ImageView myImage = new ImageView(this); 
       myImage.setImageBitmap(myBitmap); 
       linearLayout.addView(myImage); 
      } 
     } 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_edit, menu); 
     return true; 
    } 

    static final FilenameFilter IMAGE_FILTER = new FilenameFilter() { 

     @Override 
     public boolean accept(final File dir, final String name) { 
      for (String ext : EXTENSIONS) { 
       if (name.endsWith("." + ext)) { 
        return (true); 
       } 
      } 
      return (false); 
     } 
    }; 
} 
+0

확인이 [링크] (HTTP 있는지 확인하기 위해 로그인을했습니다. androhub.com/select-and-share-multiple-images/). –

답변

1

당신은 당신이 또한 파일을 작성하려는 경우 WRITE_EXTERNAL_STORAGE을 추가 할 필요가 마지막 하나를 사용하는 외부 저장을 위해 내부 저장 Context.getFilesDir()Environment.getExternalStorageDirectory()를 사용해야합니다. 귀하의 경우에는

난 당신이처럼해야 할 것 같아요 : // WWW :
static final File dir = new File(Context.getFilesDir()+"/app_imageDir/"); 

심지어 thoug 디렉토리를 잘

관련 문제