How to send an intent to select ttf file with any

2019-01-28 21:22发布

问题:

i want to send an intent when pressing a button, with this intent i want to open a file explorer by selecting it from a list of file explorers installed in device...(using "Comlete action with: ") Then, with that file explorer select a ttf file to settypeface of my textview.. The question is , i have found something related to MIME type files, but i dont understand it... Anyone can tell me how to do this, please? ;)

I have to say that, for setting typeface, i think i need a string with file path.

回答1:

The Mime type is a description of the content you're looking for. For example, a JPEG image will have a "image/jpeg" type. As for TTF files, although there is no officially registered MIME type, the most commonly used (according to Wikipedia) is

application/x-font-ttf

The documentation on Intents give an example using an ACTION_GET_CONTENT action. here's how you could use it :

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/x-font-ttf");
startActivityForResult(intent,PICKFILE_RESULT_CODE);