How to set your own mime file type

after you delve into dozens of questions about how to associate a user file with my application, I have to ask the final question: how to add the mime type using FileOutputStream?

I will try to explain: my application writes "lorenzoff" files, it is false, but say, without any extension. I know that Android uses the mime type and it’s fine, I figured it out and I added this intent filter to my manifest

<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="" android:scheme="file" android:mimeType="application/wtf" /> </intent-filter> 

Now, I want to create my new files with their contents, say

 DataOutputStream os = new DataOutputStream(new FileOutputStream("lorenzoff")); os.writeInt(1); os.writeInt(2); os.writeInt(3); os.close(); 

Checking the newly created file with the application for viewing the file system (Astro), I see that it does not have the mime type, and we arrived, I can not view it in my application (it has no association).

Question: how to write mime type so that I can read "application / wtf", checking file properties?

Thank you in advance

+4
source share
1 answer

I am afraid that you absolutely do not understand what type of MIME. You do not have to write the mime type to a file. MIME only describes the type of content (ex: file)

When the file browser tries to open the file (send the intent to android), the type of file is determined by its extension, not its contents.

After determining, the browser will launch the corresponding intention. File browsers can usually handle standard mime types, such as image, video, audio, text, or PDF.

+3
source

Source: https://habr.com/ru/post/1381544/


All Articles