5

Derzeit versuche ich, bestimmten Dateityp von SD-Karte oder mit irgendeiner Anwendung zu wählen, aber ich scheiterte, mein Code ist wie folgt,Wählen Sie docx, doc, rtf, pdf Art der Datei von der SD-Karte oder mit irgendeiner Anwendung in 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); 

aber es wählen Sie einfach jeden Dateityp aus.

+0

möglich Duplikat https://stackoverflow.com/questions/33117592/how-to-pick-few-type-of-file-via-intent-in-android – k3b

+0

Mögliche Duplikate von [Wie man einige Arten von Dateien über Intent in Android auswählen?] (Https://stackoverflow.com/questions/33117592/how-to-pick-few-type-of-file-via-intent-in- -android) – k3b

Antwort

0

versuchen diesen Code:

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

@i muss bestimmten Dateityp nicht ganz auswählen, was ist, wenn keine Anwendung installiert ist, um den rtf-Dateityp zu verarbeiten? – TheReprator