1

私は現在、インターネットで見つかったいくつかの例をテストしており、Android フォンの NFC を介して NDEF メッセージを送信しています。

Samsung Galaxy Nexus (Android 4.4.4)、S3 (Android 4.4.2)、S4 (Android 4.4.4) の 3 つの電話で電話をテストしました。

このアプリは、GN では希望どおりに機能します (メッセージを送信します) が、S3 と S4 では、メッセージの代わりにアプリのパッケージ名を送信します。

誰でもこれで私を助けることができますか? これを修正する理由または方法を知っている人はいますか? 私はAndroid開発にかなり慣れていないため、なぜこれを行っているのか完全には理解していません。

コード:

package tapit.cbstech.com.tap_it_3;

import android.app.Activity;
import android.nfc.NfcAdapter;
import android.os.Bundle;


import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter.CreateNdefMessageCallback;
import android.nfc.NfcEvent;
import android.os.Parcelable;
import android.widget.TextView;
import android.widget.Toast;


public class main extends Activity implements CreateNdefMessageCallback {
    NfcAdapter mNfcAdapter;
    TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView textView = (TextView) findViewById(R.id.textView);
        // Check for available NFC Adapter
        mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (mNfcAdapter == null) {
            Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
            finish();
            return;
        }
        // Register callback
        mNfcAdapter.setNdefPushMessageCallback(this, this);
    }

    @Override
    public NdefMessage createNdefMessage(NfcEvent event) {
        String text = ("abcdefghi");
        NdefMessage msg = new NdefMessage(
                new NdefRecord[] { NdefRecord.createMime("text/plain", 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("hello test")
                });
        return msg;
    }

    @Override
    public void onResume() {
        super.onResume();
        // Check to see that the Activity started due to an Android Beam
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            processIntent(getIntent());
        }
    }

    @Override
    public void onNewIntent(Intent intent) {
        // onResume gets called after this to handle the intent
        setIntent(intent);
    }

    /**
     * Parses the NDEF Message from the intent and prints to the TextView
     */
    void processIntent(Intent intent) {
        textView = (TextView) findViewById(R.id.textView);
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
                NfcAdapter.EXTRA_NDEF_MESSAGES);
        NdefMessage msg = (NdefMessage) rawMsgs[0];
        textView.setText(new String(msg.getRecords()[0].getPayload()));
    }
}

GNexus では「abcdefghi」を取得しますが、S3 および S4 では「tapit.cbstech.com.tap_it_3」を取得します

どんな助けでも大歓迎です!前もって感謝します!

編集:友達のS3でテストし、同じことを行い(パッケージ名を送信)、別の友達のnexus 5(Android Lを実行)でテストし、「abcdefghi」メッセージを送信しました。

4

0 に答える 0