• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

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':

Demo for NFC ACTION_TECHNOLOGY_DISCOVERED intent.

変更サマリ

差分

--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -2454,6 +2454,22 @@
24542454 </intent-filter>
24552455 </activity>
24562456
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+
24572473 </application>
24582474
24592475 <instrumentation android:name=".app.LocalSampleInstrumentation"
--- /dev/null
+++ b/samples/ApiDemos/res/xml/filter_nfc.xml
@@ -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>
--- a/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.java
+++ b/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.java
@@ -24,17 +24,20 @@ import android.content.Intent;
2424 import android.content.IntentFilter;
2525 import android.content.IntentFilter.MalformedMimeTypeException;
2626 import android.nfc.NfcAdapter;
27+import android.nfc.tech.NfcF;
2728 import android.os.Bundle;
2829 import android.util.Log;
2930 import android.widget.TextView;
3031
3132 /**
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.
3335 */
3436 public class ForegroundDispatch extends Activity {
3537 private NfcAdapter mAdapter;
3638 private PendingIntent mPendingIntent;
3739 private IntentFilter[] mFilters;
40+ private String[][] mTechLists;
3841 private TextView mText;
3942 private int mCount = 0;
4043
@@ -54,26 +57,25 @@ public class ForegroundDispatch extends Activity {
5457 mPendingIntent = PendingIntent.getActivity(this, 0,
5558 new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
5659
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
5861 IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
5962 try {
6063 ndef.addDataType("*/*");
6164 } catch (MalformedMimeTypeException e) {
6265 throw new RuntimeException("fail", e);
6366 }
64- IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECHNOLOGY_DISCOVERED);
65- tech.addDataScheme("vnd.android.nfc");
6667 mFilters = new IntentFilter[] {
6768 ndef,
68- tech,
69- new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED),
7069 };
70+
71+ // Setup a tech list for all NfcF tags
72+ mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
7173 }
7274
7375 @Override
7476 public void onResume() {
7577 super.onResume();
76- mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters);
78+ mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
7779 }
7880
7981 @Override
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/nfc/TechFilter.java
@@ -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+}