0

電話がタグを読み取ったときにアクティビティを選択する必要があります。私のアプリはアクティビティ チューザーに表示されるはずです。

私の活動のマニフェストファイルには、

        <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>

アクティビティクラスには次のものがあります:

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()}};

アクティビティ チューザーで自分のタグを表示して処理するにはどうすればよいですか? 私のタグはURIです

ありがとう

4

3 に答える 3

0

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>

これは、URIタイプNdefを検出するための適切な方法です。あなたのコードはMIMEタイプを探しています。探すべき最大のことは、あなたが持っているNdefレコードのタイプです。

この点に関する詳細については、次のリンクを使用できます:http: //developer.android.com/guide/topics/nfc/nfc.html

于 2011-11-04T20:36:25.573 に答える
0

コードはフォアグラウンドディスパッチを使用していますが、これは不要です。インテントフィルターを使用するだけです。アプリケーションがそのURIの唯一のフィルタリングである場合、アプリケーションは自動的に起動します。URIを処理できるアプリケーションが複数ある場合、アプリはアクティビティランチャーに表示されます。2番目のコードスニペットは必要ありません。Benの回答のスニペットだけを使用して、URIに合わせて変更してください。

于 2011-12-21T22:56:34.757 に答える