안녕하세요.


어제 오늘 종일 구글링 테스트 구글링 테스트했음에도 잘 동작하지 않아 이렇게 질문을 드립니다. ㅜㅜ


일단 제가 만들고자 하는 앱은 NFC를 통해서 특정 데이터를 특정앱에 전달하고 싶습니다. 


그래서 푸쉬할 폰에 데이터를 준비하고 리시브할 폰에 대면 NFC기능이 있는 앱들을 선택하는 것이 아니라 


바로 그 특정 앱을 바로 띄우려고 하고 있는데요....


그래서 조사해본 바로는 


푸시하는 쪽에서는 


public static NdefRecord newTextRecord(String text, Locale locale, boolean encodeInUtf8) {

        byte[] langBytes = locale.getLanguage().getBytes(Charset.forName("US-ASCII"));


        Charset utfEncoding = encodeInUtf8 ? Charset.forName("UTF-8") : Charset.forName("UTF-16");

        byte[] textBytes = text.getBytes(utfEncoding);


        int utfBit = encodeInUtf8 ? 0 : (1 << 7);

        char status = (char) (utfBit + langBytes.length);


        byte[] data = new byte[1 + langBytes.length + textBytes.length]; 

        data[0] = (byte) status;

        System.arraycopy(langBytes, 0, data, 1, langBytes.length);

        System.arraycopy(textBytes, 0, data, 1 + langBytes.length, textBytes.length);


         

         

//        String rtd = "application/kr.nfc.test";

        String rtd = "text/plain";

        return new NdefRecord(NdefRecord.TNF_MIME_MEDIA, rtd.getBytes(), new byte[0], data);

        

//       return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);

    }

위와 같은 방식으로 mimeType을 주었구요...



리시브하는 쪽에서 일단 메니페스트


        <activity android:name=".MainActivity"

          android:launchMode="singleInstance">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>


        <intent-filter>

                <action android:name="android.nfc.action.NDEF_DISCOVERED"/>

                <data android:mimeType="text/plain" />

            </intent-filter>

        </activity>


위와 같게 설정을 했고 (mimeType을 application/kr.nfc.test 이렇게 주면 특정 앱을 호출할수 있나요???)

    public void onCreate(Bundle savedState) {

        super.onCreate(savedState);


        setContentView(R.layout.activity_main);

        mText = (TextView) findViewById(R.id.text);

        mText.setText("Scan a tag");


        mAdapter = NfcAdapter.getDefaultAdapter(this);


        // Create a generic PendingIntent that will be deliver to this activity. The NFC stack

        // will fill in the intent with the details of the discovered tag before delivering to

        // this activity.

        mPendingIntent = PendingIntent.getActivity(this, 0,

                new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);


        // Setup an intent filter for all MIME based dispatches

        IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);

        try {

            ndef.addDataType("*/*");

        } catch (MalformedMimeTypeException e) {

            throw new RuntimeException("fail", e);

        }

        mFilters = new IntentFilter[] {

                ndef,

        };


        // Setup a tech list for all NfcF tags

        mTechLists = new String[][] { new String[] { NfcF.class.getName() } };

    }


    @Override

    public void onNewIntent(Intent intent) {

        Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);

        mText.setText("Discovered tag " + ++mCount + " with intent: " + intent);

        processTag(intent);

    }


이런식으로 받았습니다.



제가 전체 소스는 붙이지 않았지만...


이런식으로 하면 ACTION_NDEF_DISCOVERED 이걸로 등록된 액티비티를 읽는게 아니라 

폰에 설치된 다른앱들이 뜨더라구요.. 그 앱들은 ACTION_TAG_DISCOVERED 이게 설정되어 있거든요.....



책을 보면 ACTION_NDEF_DISCOVERED를 먼저 체크를 한다고 했는데 왜 ACTION_TAG_DISCOVERED 만 찾을까요....


ACTION_NDEF_DISCOVERED를 이용하여 특정앱을 바로 띄워 데이터를 보내려는데...


혹시 샘플 소스 아니면 방법 ... 알려주세요...ㅜㅜ