Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-NFC-p2p处理_Android_Nfc_Nfc P2p - Fatal编程技术网

Android-NFC-p2p处理

Android-NFC-p2p处理,android,nfc,nfc-p2p,Android,Nfc,Nfc P2p,我已经使用基于NFC的Android应用程序工作了几个月。这一个可以读写NFC标签作为解释。(关于NFCAPI的不错的文档)。我一直在玩这个应用,当我需要一些例子来遵循 以下是我当前的XML清单: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.package" android:versionCode="1" android:vers

我已经使用基于NFC的Android应用程序工作了几个月。这一个可以读写NFC标签作为解释。(关于NFCAPI的不错的文档)。我一直在玩这个应用,当我需要一些例子来遵循

以下是我当前的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>
但现在,我想将p2p功能添加到我的Android应用程序中。所以,当我把一个标签推到另一个已经安装了我的应用程序的手机上时,我希望我的应用程序会触发安卓操作选择器。而且,如果我的应用程序已经在运行,它必须处理p2p请求。
,但唯一能处理这些标签的应用程序是谷歌的一款(标签应用程序将随Nexus s一起出现),尽管我的手机上已经安装了几个NFC应用程序<有什么想法吗?有关于它的有用文档吗?

已经解决了。如果您需要在Android应用程序中处理P2P NFC请求。您需要处理nfc类型

因此,您的清单必须包括(请注意,类别是默认的):

就这些

<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() }};
    }
    <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 };