Я пару месяцев работал с Android-приложением на основе NFC. Этот может читать и писать теги NFC, как объясняют Документы Android NFC . (довольно хорошие документы о NFC API). Я играл с приложением NFCDemo , когда мне нужен пример для подражания.
Вот мой текущий XML-манифест:
<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:
<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>
Я также настроил Система диспетчеризации переднего плана :
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() }};
}
Но теперь я хочу добавить возможности p2p в мое приложение для Android. Поэтому, когда я отправляю тег на другой телефон с уже установленным приложением, я хочу, чтобы приложение «Выбор действий Android» запускалось вместе с моим приложением. А также, если мое приложение уже запущено, оно должно обработать p2p-запрос.
Я мог бы правильно нажимать теги p2p, используя документы Android об этом , но единственное приложение, которое может обрабатывать эти теги, - это приложение Google (приложение Тегов, которое становится с Nexus S), несмотря на то, что у меня несколько NFC приложения уже установлены в моем телефоне. Есть идеи? Любая полезная документация об этом?