NFC and MIME TYPE are case sensitive

I try only the basic version of NFC, but then I find that MIME TYPE is case sensitive. The package name for my application has one uppercase letter.

Package Name: com.example.Main_Activity

<intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimeType="application/com.example.Main_Activity"/>
</intent-filter>

Does anyone know about this?

thanks

+4
source share
2 answers

MIME types are case insensitive according to RFC. However, the matting of the Android intent filter is case-sensitive. To overcome this problem, you should always use only small MIME types.

, NFC API MIME, MIME . NdefRecord.createMime() MIME . .

NdefRecord r1 = NdefRecord.createMime("text/ThisIsMyMIMEType", ...);
NdefRecord r2 = NdefRecord.createMime("text/tHISiSmYmimetYPE", ...);
NdefRecord r3 = NdefRecord.createMime("text/THISISMYMIMETYPE", ...);
NdefRecord r4 = NdefRecord.createMime("text/thisismymimetype", ...);

MIME:

+----------------------------------------------------------+
| MIME:text/thisismymimetype | ...                         |
+----------------------------------------------------------+

, :

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/thisismymimetype" />
</intent-filter>
+2

. , , . , . MIME . , , MIME TYPE NFC - . . , , CAPS. .

, .

public NdefMessage createNdefMessage(NfcEvent event) {
        String text = ("Beam me up, Android!\n\n" +
                "Beam Time: " + System.currentTimeMillis());
        NdefMessage msg = new NdefMessage(
                new NdefRecord[] { NdefRecord.createMime(
                        "application/com.example.main_activity", text.getBytes())
         /**
          * The Android Application Record (AAR) is commented out. When a device
          * receives a push with an AAR in it, the application specified in the AAR
          * is guaranteed to run. The AAR overrides the tag dispatch system.
          * You can add it back in to guarantee that this
          * activity starts when receiving a beamed message. For now, this code
          * uses the tag dispatch system.
          */
          ,NdefRecord.createApplicationRecord("com.example.Main_Activity")
        });
        return msg;
    }
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/com.example.main_activity"/>
</intent-filter>
0

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


All Articles