2012-05-10 3 views
1

안 빔 터치 :나는 특별 활동 A가 데이터를 전송 할 수있는 응용 프로그램이 모드

디바이스 1 활동가에 있고 앱이 경우에도 1 디바이스 (1 디바이스는 상관없이,와 페어링 시작되지 않음) 데이터가 성공적으로 빔 터치 후 transfferred. 활동 A는 의도 필터가 있습니다.

 <intent-filter> 
      <action android:name="android.nfc.action.NDEF_DISCOVERED" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="application/de.my.app" /> 
     </intent-filter> 

on이 필요한 푸시를 수행합니다.

하지만 다른 활동 B에서 오전 때, 이것은 또한

  1. 다른 장치 앱이 시작되면 터치 모드가 두 장치에 표시되는 확인 응용 프로그램
  2. 을 시작합니다. 어떤 장치가 빔을 바꾸기를 원하지 않습니다. 안드로이드 데스크탑에서 장치를 페어링하면 빔 대화 상자가 표시되지 않습니다. 방금 진동이 적습니다. 그게 내가 원하는 걸. 가능한가?

미리 감사드립니다. 활동 B에서

답변

5

, 당신은 어떤 NFC 의도를 무시 전경 파견 켜고 안드로이드 빔 메시지를 전송하지 않도록 설정할 수 있습니다 다음 Ndef 기술만을 필터링하여

private NfcAdapter nfcAdapter; 

protected void onCreate(Bundle savedInstanceState) { 
    ... 
    nfcAdapter = NfcAdapter.getDefaultAdapter(this); 
    // turn off sending Android Beam 
    nfcAdapter.setNdefPushMessage(null, this); 
} 

protected void onResume() { 
    // catch all NFC intents 
    Intent intent = new Intent(getApplicationContext(), getClass()); 
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); 
    nfcAdapter.enableForegroundDispatch(this, pintent, null, null); 
} 

protected void onPause() { 
    nfcAdapter.disableForegroundDispatch(this); 
} 

protected void onNewIntent(Intent intent) { 
    if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()) { 
    return; // ignore NFC intents 
    } 
} 

당신이 좀 더 구체적인 만들 수를 PendingIntent 및/또는 onNewIntent() 개체가 지원하는 다른 기술을 확인하십시오. Android Beam의 의도는 항상 Ndef 기술이며 다른 기술은 없습니다.

+0

비슷한 상황에서, 나는 onNewIntent()가 ACTION_NDEF_DISCOVERED와 함께 호출된다는 것을 알아 차렸다. 내 목표가 수신 활동의 (다시) 실행을 억제하는 것이라면 intent.getAction() == ACTION_NDEF_DISCOVERED 일 때 즉시 반환해야합니까? 감사. – gcl1