2011-08-30 3 views
0

2 개월 동안 NFC 기반 Android 애플리케이션으로 작업 해 왔습니다. 이건 & NFC 태그를 Android NFC docs 설명으로 쓸 수 있습니다. (NFC API에 관한 꽤 좋은 문서들). 내가 따라야 할 예제가 필요할 때 NFCDemo 앱을 가지고 놀았습니다. 내가 지금Android NFC P2P 처리

public void setUpForegroundDispatchSystem(Activity activity) { 
     this.nfcAdapter = NfcAdapter.getDefaultAdapter(activity); 

     this.pendingIntent = PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 

     IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); 
     this.intentFiltersArray = new IntentFilter[] { ndef }; 
     this.techListsArray = new String[][] { 
       new String[] { MifareUltralight.class.getName(), 
         Ndef.class.getName(), NfcA.class.getName() }, 
       new String[] { MifareClassic.class.getName(), 
         Ndef.class.getName(), NfcA.class.getName() }, 
       new String[] { MifareUltralight.class.getName(), 
         NdefFormatable.class.getName(), NfcA.class.getName() }, 
       new String[] { Ndef.class.getName(), NfcV.class.getName() }, 
       new String[] { NfcF.class.getName() }}; 
    } 

그러나 : 나는 또한 Foreground Dispatch System을 구성한

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> 
    <tech-list> 
     <tech>android.nfc.tech.MifareUltralight</tech> 
     <tech>android.nfc.tech.Ndef</tech> 
     <tech>android.nfc.tech.NfcA</tech> 
    </tech-list> 
    <tech-list> 
     <tech>android.nfc.tech.MifareClassic</tech> 
     <tech>android.nfc.tech.Ndef</tech> 
     <tech>android.nfc.tech.NfcA</tech> 
    </tech-list> 
    <tech-list> 
      <tech>android.nfc.tech.MifareUltralight</tech> 
      <tech>android.nfc.tech.NdefFormatable</tech> 
      <tech>android.nfc.tech.NfcA</tech> 
    </tech-list> 
    <tech-list> 
      <tech>android.nfc.tech.Ndef</tech> 
      <tech>android.nfc.tech.NfcV</tech> 
    </tech-list> 
    <tech-list> 
     <tech>android.nfc.tech.NfcF</tech> 
    </tech-list> 
</resources> 

: 여기

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.my.package" 
     android:versionCode="1" 
     android:versionName="1.0.0"> 
    <uses-sdk android:minSdkVersion="10" /> 
    <uses-feature android:name="android.hardware.nfc" android:required="true" /> 
    <uses-permission android:name="android.permission.NFC" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <application android:icon="@drawable/icon" 
       android:label="@string/app_name" 
       android:launchMode="singleTask"> 
     <activity android:name=".MainActivity" 
        android:label="@string/app_name" 
        android:screenOrientation="portrait"> 
      <!-- the following actions and categories let the App be in Android Action Chooser and also Scan Tags when the app si running -->  
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> <!-- Main application --> 
       <category android:name="android.intent.category.LAUNCHER" /><!-- Logo Display in App List--> 
      </intent-filter> 

      <intent-filter> 
       <action android:name="android.nfc.action.TECH_DISCOVERED"/> 
      </intent-filter> 
      <meta-data android:name="android.nfc.action.TECH_DISCOVERED" 
           android:resource="@xml/nfc_tech_filter" /> 
      <intent-filter> 
       <action android:name="android.nfc.action.TAG_DISCOVERED"/> 
      </intent-filter> 

     </activity> 
    <activity android:name=".RouteActivity"> 
      <intent-filter> 
       <action android:name="android.nfc.action.NDEF_DISCOVERED"/> 
       <category android:name="android.intent.category.DEFAULT"/> 
       <data android:host="www.my.custom.tag.com" android:scheme="http" /> 
      </intent-filter> 
    </activity> 
</application> 
</manifest> 

가 tech_filter 파일의 정의는 다음과 같습니다

내 현재 XML 매니페스트입니다 내 안드로이드 응용 프로그램에 P2P 기능을 추가하고 싶습니다. 그래서 내 앱이 이미 설치된 다른 휴대 전화에 태그를 푸시하면 안드로이드 액션 선택기가 내 앱으로 실행되기를 원합니다. 또한 내 앱이 이미 실행 중이면 P2P 요청을 처리해야합니다. I could push p2p Tags correctly, using the Android docs about it하지만이 태그를 처리 할 수있는 앱은 휴대 전화에 이미 여러 개의 NFC 앱이 설치되어 있어도 Google의 앱 (Nexus S로 태그 애플리케이션)입니다. 아이디어가 있으십니까? 그것에 관한 유용한 문서가 있습니까?

답변

1

이미 해결되었습니다. Android 앱에서 P2P NFC 요청을 처리해야하는 경우 android.nfc.action.TAG_DISCOVERED nfc 유형을 처리해야합니다.

그래서 매니페스트가 포함되어야합니다 (범주는 DEFAULT이다) :

<intent-filter> 
     <action android:name="android.nfc.action.TAG_DISCOVERED"/> 
     <category android:name="android.intent.category.DEFAULT"/> 
    </intent-filter> 

이 안드로이드 액션 선택기를 표시하고 앱이 여기에 표시됩니다. 당신은 또한 전경 기능을 추가 싶어하는 경우 (즉, 원래의 볼 위에 쓴)이 방법으로 포 그라운드 디스패치 시스템을 수정해야합니다

IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); 
IntentFilter tag = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); 
this.intentFiltersArray = new IntentFilter[] { ndef , tag }; 

을 그리고 그게 다야.