development
リビジョン | 06bef9df0b13209e1c6b40709f6a9a976f58e230 (tree) |
---|---|
日時 | 2011-01-26 07:44:37 |
作者 | Jeff Hamilton <jham@andr...> |
コミッター | Android Git Automerger |
am 7a11acd9: am e0fbd3ff: Demo for NFC ACTION_TECHNOLOGY_DISCOVERED intent.
* commit '7a11acd92bec5e7a089bdb248a78589491962c76':
@@ -2454,6 +2454,22 @@ | ||
2454 | 2454 | </intent-filter> |
2455 | 2455 | </activity> |
2456 | 2456 | |
2457 | + <activity android:name=".nfc.TechFilter" android:label="NFC/TechFilter"> | |
2458 | + <intent-filter> | |
2459 | + <action android:name="android.intent.action.MAIN" /> | |
2460 | + <category android:name="android.intent.category.SAMPLE_CODE" /> | |
2461 | + </intent-filter> | |
2462 | + | |
2463 | + <!-- Add a technology filter --> | |
2464 | + <intent-filter> | |
2465 | + <action android:name="android.nfc.action.TECH_DISCOVERED" /> | |
2466 | + </intent-filter> | |
2467 | + | |
2468 | + <meta-data android:name="android.nfc.action.TECH_DISCOVERED" | |
2469 | + android:resource="@xml/filter_nfc" | |
2470 | + /> | |
2471 | + </activity> | |
2472 | + | |
2457 | 2473 | </application> |
2458 | 2474 | |
2459 | 2475 | <instrumentation android:name=".app.LocalSampleInstrumentation" |
@@ -0,0 +1,28 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<!-- Copyright (C) 2011 The Android Open Source Project | |
3 | + | |
4 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + you may not use this file except in compliance with the License. | |
6 | + You may obtain a copy of the License at | |
7 | + | |
8 | + http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + | |
10 | + Unless required by applicable law or agreed to in writing, software | |
11 | + distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + See the License for the specific language governing permissions and | |
14 | + limitations under the License. | |
15 | +--> | |
16 | +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
17 | + <!-- capture anything using NfcF --> | |
18 | + <tech-list> | |
19 | + <tech>android.nfc.tech.NfcF</tech> | |
20 | + </tech-list> | |
21 | + | |
22 | + <!-- capture all MIFARE Classics with NDEF payloads --> | |
23 | + <tech-list> | |
24 | + <tech>android.nfc.tech.NfcA</tech> | |
25 | + <tech>android.nfc.tech.MifareClassic</tech> | |
26 | + <tech>android.nfc.tech.Ndef</tech> | |
27 | + </tech-list> | |
28 | +</resources> |
@@ -24,17 +24,20 @@ import android.content.Intent; | ||
24 | 24 | import android.content.IntentFilter; |
25 | 25 | import android.content.IntentFilter.MalformedMimeTypeException; |
26 | 26 | import android.nfc.NfcAdapter; |
27 | +import android.nfc.tech.NfcF; | |
27 | 28 | import android.os.Bundle; |
28 | 29 | import android.util.Log; |
29 | 30 | import android.widget.TextView; |
30 | 31 | |
31 | 32 | /** |
32 | - * An example of how to use the NFC foreground dispatch APIs. | |
33 | + * An example of how to use the NFC foreground dispatch APIs. This will intercept any MIME data | |
34 | + * based NDEF dispatch as well as all dispatched for NfcF tags. | |
33 | 35 | */ |
34 | 36 | public class ForegroundDispatch extends Activity { |
35 | 37 | private NfcAdapter mAdapter; |
36 | 38 | private PendingIntent mPendingIntent; |
37 | 39 | private IntentFilter[] mFilters; |
40 | + private String[][] mTechLists; | |
38 | 41 | private TextView mText; |
39 | 42 | private int mCount = 0; |
40 | 43 |
@@ -54,26 +57,25 @@ public class ForegroundDispatch extends Activity { | ||
54 | 57 | mPendingIntent = PendingIntent.getActivity(this, 0, |
55 | 58 | new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); |
56 | 59 | |
57 | - // Setup intent filters for all types of NFC dispatches to intercept all discovered tags | |
60 | + // Setup an intent filter for all MIME based dispatches | |
58 | 61 | IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); |
59 | 62 | try { |
60 | 63 | ndef.addDataType("*/*"); |
61 | 64 | } catch (MalformedMimeTypeException e) { |
62 | 65 | throw new RuntimeException("fail", e); |
63 | 66 | } |
64 | - IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECHNOLOGY_DISCOVERED); | |
65 | - tech.addDataScheme("vnd.android.nfc"); | |
66 | 67 | mFilters = new IntentFilter[] { |
67 | 68 | ndef, |
68 | - tech, | |
69 | - new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED), | |
70 | 69 | }; |
70 | + | |
71 | + // Setup a tech list for all NfcF tags | |
72 | + mTechLists = new String[][] { new String[] { NfcF.class.getName() } }; | |
71 | 73 | } |
72 | 74 | |
73 | 75 | @Override |
74 | 76 | public void onResume() { |
75 | 77 | super.onResume(); |
76 | - mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters); | |
78 | + mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists); | |
77 | 79 | } |
78 | 80 | |
79 | 81 | @Override |
@@ -0,0 +1,51 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2011 Google Inc. | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License | |
15 | + */ | |
16 | + | |
17 | +package com.example.android.apis.nfc; | |
18 | + | |
19 | +import com.example.android.apis.R; | |
20 | + | |
21 | +import android.app.Activity; | |
22 | +import android.content.Intent; | |
23 | +import android.nfc.NfcAdapter; | |
24 | +import android.os.Bundle; | |
25 | +import android.widget.TextView; | |
26 | + | |
27 | +public class TechFilter extends Activity { | |
28 | + private TextView mText; | |
29 | + private int mCount = 0; | |
30 | + | |
31 | + @Override | |
32 | + public void onCreate(Bundle savedState) { | |
33 | + super.onCreate(savedState); | |
34 | + | |
35 | + setContentView(R.layout.foreground_dispatch); | |
36 | + mText = (TextView) findViewById(R.id.text); | |
37 | + | |
38 | + Intent intent = getIntent(); | |
39 | + String action = intent.getAction(); | |
40 | + if (NfcAdapter.ACTION_TECHNOLOGY_DISCOVERED.equals(action)) { | |
41 | + mText.setText("Discovered tag " + ++mCount + " with intent: " + intent); | |
42 | + } else { | |
43 | + mText.setText("Scan a tag"); | |
44 | + } | |
45 | + } | |
46 | + | |
47 | + @Override | |
48 | + public void onNewIntent(Intent intent) { | |
49 | + mText.setText("Discovered tag " + ++mCount + " with intent: " + intent); | |
50 | + } | |
51 | +} |