5

В настоящее время я пытаюсь выбрать конкретный тип файла с SD-карты или с любым приложением, но я потерпел неудачу, мой код выглядит следующим образом:Выберите файл docx, doc, rtf, pdf с SD-карты или с любым приложением в android

Intent intent; 
     if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) 
      intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 
     else 
      intent = new Intent(Intent.ACTION_GET_CONTENT); 

     intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
     intent.addCategory(Intent.CATEGORY_OPENABLE); 
     intent.setType("application/pdf|application/msword|application/vnd.openxmlformats-officedocument.wordprocessingml.document" + 
       "|application/vnd.openxmlformats-officedocument.wordprocessingml.template" + 
       "|application/vnd.ms-word.document.macroEnabled.12" + 
       "|application/vnd.ms-word.template.macroEnabled.12" + 
       "!application/vnd.ms-word.template.macroEnabled.12|application/rtf"); 

     startActivityForResult(intent, Constants.ImagePicker.REQ_PICK_RESUME); 

, но он просто выбирает каждый тип файла.

+0

возможный дубликат https://stackoverflow.com/questions/33117592/how-to-pick-few-type-of-file-via-intent-in-android – k3b

+0

Возможный дубликат [как выбрать несколько типов файлов с помощью намерения в android?] (Https://stackoverflow.com/questions/33117592/how-to-pick-few-type-of-file-via-intent-in -android) – k3b

ответ

0

попробовать этот код:

Intent intent = new Intent(); 
intent.setType("application/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent, "Select file"),1); 
+0

@i нужно выбрать конкретный тип файла не целое, а что, если нет приложения, установленного для обработки типа файла rtf? – TheReprator