Question

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>
Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top