Skip to content

Commit a9e746b

Browse files
committed
new NFC Beam stuff
1 parent 2c23390 commit a9e746b

File tree

5 files changed

+496
-31
lines changed

5 files changed

+496
-31
lines changed

SensorDemos/AndroidManifest.xml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
package="com.oreilly.demo.android.pa.sensordemo"
44
android:versionCode="1"
55
android:versionName="1.0">
6+
7+
<!--
8+
Change the uses-sdk to
9+
<uses-sdk android:minSdkVersion="9" />
10+
to run on a 2.3.1 device and be able to
11+
detect android.nfc.action.NDEF_DISCOVERED intents (and thus read a nfc tag)
12+
-->
13+
<uses-sdk android:minSdkVersion="10" />
14+
15+
<uses-feature android:name="android.hardware.nfc" android:required="true" />
16+
<uses-permission android:name="android.permission.NFC" />
17+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
18+
<uses-permission android:name="android.permission.VIBRATE" />
19+
620
<application android:icon="@drawable/icon" android:label="@string/app_name">
721
<activity android:name=".MainActivity"
822
android:label="@string/app_name">
@@ -49,24 +63,19 @@
4963
android:resource="@xml/nfcfilter"
5064
/>
5165
</activity>
66+
67+
<activity android:name=".NFC40">
68+
<intent-filter>
69+
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
70+
<category android:name="android.intent.category.DEFAULT"/>
71+
<data android:mimeType="application/com.oreilly.demo.android.pa.sensordemo"/>
72+
</intent-filter>
73+
</activity>
5274

5375
<service android:name=".Accessibility">
5476
<intent-filter>
5577
<action android:name="android.accessibilityservice.AccessibilityService" />
5678
</intent-filter>
5779
</service>
5880
</application>
59-
60-
<!--
61-
Change the uses-sdk to
62-
<uses-sdk android:minSdkVersion="9" />
63-
to run on a 2.3.1 device and be able to
64-
detect android.nfc.action.NDEF_DISCOVERED intents (and thus read a nfc tag)
65-
-->
66-
<uses-sdk android:minSdkVersion="10" />
67-
68-
<uses-feature android:name="android.hardware.nfc" android:required="true" />
69-
<uses-permission android:name="android.permission.NFC" />
70-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
71-
<uses-permission android:name="android.permission.VIBRATE" />
7281
</manifest>

SensorDemos/res/layout/main.xml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,121 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="match_parent"
4-
android:layout_height="match_parent"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
55
>
66
<ScrollView
7-
android:layout_width="match_parent"
8-
android:layout_height="match_parent"
7+
android:layout_width="fill_parent"
8+
android:layout_height="fill_parent"
99
>
1010
<LinearLayout
1111
android:orientation="vertical"
12-
android:layout_width="match_parent"
13-
android:layout_height="match_parent"
12+
android:layout_width="fill_parent"
13+
android:layout_height="fill_parent"
1414
>
1515
<Button
1616
android:id="@+id/sensorsaccel"
17-
android:layout_width="match_parent"
17+
android:layout_width="fill_parent"
1818
android:layout_height="wrap_content"
1919
android:paddingTop="5dp"
2020
android:paddingBottom="5dp"
2121
android:text="Sensor - Accelerometer"
2222
/>
2323
<Button
2424
android:id="@+id/sensorgyroscope"
25-
android:layout_width="match_parent"
25+
android:layout_width="fill_parent"
2626
android:layout_height="wrap_content"
2727
android:paddingTop="5dp"
2828
android:paddingBottom="5dp"
2929
android:text="Sensor - Gyroscope"
3030
/>
3131
<Button
3232
android:id="@+id/sensorrotate"
33-
android:layout_width="match_parent"
33+
android:layout_width="fill_parent"
3434
android:layout_height="wrap_content"
3535
android:paddingTop="5dp"
3636
android:paddingBottom="5dp"
3737
android:text="Sensor - Rotational Vector"
3838
/>
3939
<Button
4040
android:id="@+id/sensorlinear"
41-
android:layout_width="match_parent"
41+
android:layout_width="fill_parent"
4242
android:layout_height="wrap_content"
4343
android:paddingTop="5dp"
4444
android:paddingBottom="5dp"
4545
android:text="Sensor - Linear Acceleration"
4646
/>
4747
<Button
4848
android:id="@+id/sensorgravity"
49-
android:layout_width="match_parent"
49+
android:layout_width="fill_parent"
5050
android:layout_height="wrap_content"
5151
android:paddingTop="5dp"
5252
android:paddingBottom="5dp"
5353
android:text="Sensor - Gravity"
5454
/>
5555
<Button
5656
android:id="@+id/sensorlight"
57-
android:layout_width="match_parent"
57+
android:layout_width="fill_parent"
5858
android:layout_height="wrap_content"
5959
android:paddingTop="5dp"
6060
android:paddingBottom="5dp"
6161
android:text="Sensor - Light"
6262
/>
6363
<Button
6464
android:id="@+id/sensormagnetic"
65-
android:layout_width="match_parent"
65+
android:layout_width="fill_parent"
6666
android:layout_height="wrap_content"
6767
android:paddingTop="5dp"
6868
android:paddingBottom="5dp"
6969
android:text="Sensor - Magnetic"
7070
/>
7171
<Button
7272
android:id="@+id/sensorpressure"
73-
android:layout_width="match_parent"
73+
android:layout_width="fill_parent"
7474
android:layout_height="wrap_content"
7575
android:paddingTop="5dp"
7676
android:paddingBottom="5dp"
7777
android:text="Sensor - Pressure"
7878
/>
7979
<Button
8080
android:id="@+id/sensorproximity"
81-
android:layout_width="match_parent"
81+
android:layout_width="fill_parent"
8282
android:layout_height="wrap_content"
8383
android:paddingTop="5dp"
8484
android:paddingBottom="5dp"
8585
android:text="Sensor - Proximity"
8686
/>
8787
<Button
8888
android:id="@+id/sensortemp"
89-
android:layout_width="match_parent"
89+
android:layout_width="fill_parent"
9090
android:layout_height="wrap_content"
9191
android:paddingTop="5dp"
9292
android:paddingBottom="5dp"
9393
android:text="Sensor - Temperature"
9494
/>
9595
<Button
9696
android:id="@+id/gesture"
97-
android:layout_width="match_parent"
97+
android:layout_width="fill_parent"
9898
android:layout_height="wrap_content"
9999
android:paddingTop="5dp"
100100
android:paddingBottom="5dp"
101101
android:text="Gesture Input"
102102
/>
103103
<Button
104104
android:id="@+id/nfc233"
105-
android:layout_width="match_parent"
105+
android:layout_width="fill_parent"
106106
android:layout_height="wrap_content"
107107
android:paddingTop="5dp"
108108
android:paddingBottom="5dp"
109109
android:text="NFC - 2.3.3"
110110
/>
111+
<Button
112+
android:id="@+id/nfc40"
113+
android:layout_width="fill_parent"
114+
android:layout_height="wrap_content"
115+
android:paddingTop="5dp"
116+
android:paddingBottom="5dp"
117+
android:text="NFC - 4.0 (Beam Example)"
118+
/>
111119
</LinearLayout>
112120
</ScrollView>
113121
</FrameLayout>

SensorDemos/res/layout/nfc40.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent"
6+
android:background="#fff"
7+
>
8+
<TextView
9+
android:id="@+id/headermsg"
10+
android:layout_width="fill_parent"
11+
android:layout_height="wrap_content"
12+
android:padding="10dp"
13+
android:textColor="#000"
14+
android:text="Example of Android NFC Beam (Andorid 4.0+)"
15+
/>
16+
<Button
17+
android:id="@+id/close"
18+
android:layout_width="fill_parent"
19+
android:layout_height="wrap_content"
20+
android:padding="5dp"
21+
android:textColor="#000"
22+
android:text="Close"
23+
/>
24+
<Button
25+
android:id="@+id/beamon"
26+
android:layout_width="fill_parent"
27+
android:layout_height="wrap_content"
28+
android:padding="10dp"
29+
android:textColor="#000"
30+
android:text="Beam On"
31+
/>
32+
<Button
33+
android:id="@+id/beamnow"
34+
android:layout_width="fill_parent"
35+
android:layout_height="wrap_content"
36+
android:padding="10dp"
37+
android:textColor="#000"
38+
android:text="Beam Now"
39+
/>
40+
<TextView
41+
android:id="@+id/tagid"
42+
android:layout_width="fill_parent"
43+
android:layout_height="wrap_content"
44+
android:padding="10dp"
45+
android:textColor="#000"
46+
android:text="TagID: UNKNOWN"
47+
/>
48+
<TextView
49+
android:id="@+id/tagtype"
50+
android:layout_width="fill_parent"
51+
android:layout_height="wrap_content"
52+
android:padding="10dp"
53+
android:textColor="#000"
54+
android:text="TagType: UNKNOWN"
55+
/>
56+
<TextView
57+
android:id="@+id/tagdata"
58+
android:layout_width="fill_parent"
59+
android:layout_height="wrap_content"
60+
android:padding="10dp"
61+
android:textColor="#000"
62+
android:text="TagData: NONE"
63+
/>
64+
</LinearLayout>

SensorDemos/src/com/oreilly/demo/android/pa/sensordemo/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,13 @@ public void onClick(View v) {
106106
}
107107

108108
});
109+
110+
findViewById(R.id.nfc40).setOnClickListener(new View.OnClickListener() {
111+
112+
public void onClick(View v) {
113+
startActivity(new Intent(getBaseContext(), NFC40.class)); // Launch the NFC 4.0 (SDK 14) Example
114+
}
115+
116+
});
109117
}
110118
}

0 commit comments

Comments
 (0)