1
Android 프로젝트에서 작업 중입니다. 일부 디렉토리에 액세스 할 수 있도록 ContentProvider를 제공해야합니다. FileProvider 나에게 좋은 해결책입니다. FileProvider를 사용하여 디렉토리의 파일 목록을 검색 할 수 있습니까?FileProvider를 사용하여 파일 목록을 얻는 방법
Android 프로젝트에서 작업 중입니다. 일부 디렉토리에 액세스 할 수 있도록 ContentProvider를 제공해야합니다. FileProvider 나에게 좋은 해결책입니다. FileProvider를 사용하여 디렉토리의 파일 목록을 검색 할 수 있습니까?FileProvider를 사용하여 파일 목록을 얻는 방법
사용자 ACTION_SEND_MULTIPLE 여러가 URI
// Set up an Intent to send back to apps that request files
mResultIntent = new Intent("com.yourpacakgename.ACTION_SEND_MULTIPLE");
// Get the files/res subdirectory;
File mResDir = new File(getFilesDir(), "res");
// Get the files in the res subdirectory
File[] mResFiles = mResDir.listFiles();
// Uri list
ArrayList<Uri> uriArrayList = new ArrayList<Uri>();
// Set the Activity's result to null to begin with
setResult(Activity.RESULT_CANCELED, null);
Uri fileUri = null;
for (int i = 0; i < mResFiles.length; i++) {
Log.i(TAG, mResFiles[i].getName());
// Use the FileProvider to get a content URI
try {
fileUri = FileProvider.getUriForFile(this, this.getPackageName() + ".fileprovider", mResFiles[i]);
// add current file uri to the list
uriArrayList.add(fileUri);
} catch (Exception e) {
Log.e(TAG, "The selected file can't be shared: " + mResFiles[i].getPath());
fileUri = null;
}
}
if (uriArrayList.size() != 0) {
// Put the UriList Intent
mResultIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriArrayList);
mResultIntent.setType("application/*");
// Grant temporary read permission to all apps
mResultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// if you want send this to a specific app
//grantUriPermission("pacakgename of client app", fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
// Set the result
this.setResult(Activity.RESULT_OK, mResultIntent);
} else {
// Set the result to failed
mResultIntent.setDataAndType(null, "");
this.setResult(RESULT_CANCELED, mResultIntent);
}
// Finish Activity and return Result to Caller
finish();
당신은 무엇을 시도 보내? https://developer.android.com/reference/android/support/v4/content/FileProvider.html – MobileMon
예 시도했지만 특정 이름으로 하나의 파일을 가져 오는 방법은 하나뿐입니다. 'File imagePath = new File (Context. getFilesDir(), "images"); 파일 newFile = 새 파일 (imagePath, "default_image.jpg"); Uri contentUri = getUriForFile (getContext(), "com.mydomain.fileprovider", newFile); ' 내가 dirrectory에있는 파일의 전체 목록을 얻을 수있는 방법을 fild 필요 – Misha