2011-11-03 1 views
0

Je dois choisir mon activité lorsque le téléphone lit une étiquette. Mon application doit être visible sur le sélecteur d'activité.Impossible de lire l'étiquette nfc en mode prioritaire

Dans le fichier manifeste de mon activité, j'ai

 <activity android:name=".WaitingPayment" android:noHistory="true" 
     android:theme="@android:style/Theme.NoTitleBar" 
     android:screenOrientation="portrait" android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.nfc.action.NDEF_DISCOVERED" /> 
      <data android:mimeType="*/*" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

Dans la classe d'activité j'ai:

nfcAdapter = NfcAdapter.getDefaultAdapter(this); 

    pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 
    ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); 
    try { 
     ndef.addDataType("*/*"); /* Handles all MIME based dispatches. 
             You should specify only the ones that you need. */ 
    } 
    catch (MalformedMimeTypeException e) { 
     throw new RuntimeException("fail", e); 
    } 
    this.intentFiltersArray = new IntentFilter[] {ndef}; 
    this.techListsArray = new String[][] { new String[] { MifareUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()}}; 

Qu'est-ce que je peux faire pour voir mon tag sur l'activité chooser et le manipuler? Mon étiquette c'est un URI

grâce

Répondre

0

vous pouvez essayer cela pour un URI:

<intent-filter> 
    <action android:name="android.nfc.action.NDEF_DISCOVERED" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:scheme="http" 
     android:host="developer.android.com" 
     android:pathPrefix="/index.html" /> 
</intent-filter> 

Ce serait le moyen approprié pour détecter un type d'URI Ndef. Votre code recherche le type MIME. La plus grande chose à rechercher est le type d'enregistrement Ndef que vous avez.

Vous pouvez utiliser ce lien pour plus d'informations à cet égard: http://developer.android.com/guide/topics/nfc/nfc.html

0

votre code à l'aide dispatching de premier plan, qui est inutile. Utilisez simplement le filtre d'intention. Si votre application est le seul filtrage pour cet URI, il se lancera automatiquement. Si plusieurs applications peuvent gérer l'URI, votre application apparaîtra dans le lanceur d'activité. Vous n'avez pas besoin du deuxième extrait de code, juste l'extrait dans la réponse de Ben et le modifier pour votre URI.

0

L'activité apparaît Chooser seulement s'il y a plus de 1 application ayant les mêmes filter.As intention que vous avez Uri écrit à votre Tag, vous devez utiliser

<intent-filter> 
<action android:name="android.nfc.action.NDEF_DISCOVERED"/> 
<category android:name="android.intent.category.DEFAULT"/> 
<data android:scheme="http" 
    android:host="developer.android.com" 
    android:pathPrefix="/index.html" /> 
</intent-filter> 
Questions connexes