How to get intent filter MimeType

android, android-intent, mime-types, ndef

Solution

Here is a simplified version of how I handle csv files and text files in my app. I hope this help:

@Override
public void onNewIntent(final Intent intent)
{
    super.onNewIntent(intent);
    String type = intent.getType();
    String action = intent.getAction();
    if ("text/csv".equals(type) || "text/comma-separated-values".equals(type))
    {
        // Handle CSV file being sent
        handleSendCSV(intent); 
    } 
    else if("text/plain".equals(type) && Intent.ACTION_SEND.equals(action))
    {
        // Handle plaintext sent
        handlePlainText(intent);
    } 
    else
    {
        //Alert of some error
        doAlertDialog("Error.", "Invalid file type.");
    }
}

Edit-

Added:

String action = intent.getAction();

So the code would be complete.

Problem

I have the following filters in my application. I want to be able to launch the same app using three different mimeTypes. Later on I read the NDEF message, but how can I check what mime type was used to launch the app so I can handle the NDEF message data accordingly? ``` <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="text/product" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="text/pesticide" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="text/seed" /> </intent-filter> ```

Original source