Skip to content

Commit d5a3d19

Browse files
committed
modified for nfc example.
1 parent d96ed77 commit d5a3d19

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

.gitkeep

Whitespace-only changes.

nfc-and-felica/AndroidManifest.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
android:versionName="1.0" >
66

77
<uses-sdk android:minSdkVersion="10" />
8-
8+
<uses-permission android:name="android.permission.NFC"/>
99
<application
1010
android:icon="@drawable/ic_launcher"
1111
android:label="@string/app_name" >
1212
<activity
1313
android:name=".NfcActivity"
1414
android:label="@string/app_name" >
1515
<intent-filter>
16+
<action android:name="android.nfc.action.TECH_DISCOVERED" />
17+
<category android:name="android.intent.category.DEFAULT" />
1618
<action android:name="android.intent.action.MAIN" />
17-
1819
<category android:name="android.intent.category.LAUNCHER" />
1920
</intent-filter>
21+
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/filter_nfc" />
2022
</activity>
2123
</application>
22-
2324
</manifest>

nfc-and-felica/res/xml/filter_nfc.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
3+
<tech-list><tech>android.nfc.tech.NfcF</tech></tech-list>
4+
</resources>

nfc-and-felica/src/net/yuki24/exercise/nfc/NfcActivity.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public void onCreate(Bundle savedInstanceState) {
2323
byte[] idm = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
2424

2525
try {
26-
Uri uri = Uri.parse("market://details?id=com.main.typograffit");
27-
Intent i = new Intent(Intent.ACTION_VIEW, uri);
26+
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.main.typograffit"));
2827
PushIntentSegment segment = new PushIntentSegment(i);
2928
PushCommand pushCommand = new PushCommand(new IDm(idm), segment);
3029
FeliCaLib.execute(tag, pushCommand);

nfc-and-felica/src/net/yuki24/exercise/nfc/PushCommand.java

+13-19
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import net.kazzz.felica.lib.FeliCaLib.CommandPacket;
1010
import net.kazzz.felica.lib.FeliCaLib.IDm;
1111

12+
import com.felicanetworks.mfc.PushIntentSegment;
1213
import com.felicanetworks.mfc.PushSegment;
1314

1415
public class PushCommand extends CommandPacket {
1516
private static final Charset URL_CHARSET = Charset.forName("iso8859-1");
1617
private static final Charset ICC_CHARSET = Charset.forName("iso8859-1");
17-
//private static final Charset STARTUP_PARAM_CHARSET = Charset.forName("Shift_JIS");
1818
public static final byte PUSH = (byte) 0xb0;
1919

2020
static {
@@ -33,16 +33,16 @@ private static byte[] packContent(byte[] segments) {
3333
}
3434

3535
private static byte[] packSegment(byte[]... segments) {
36-
int bytes = 3; // 個別部数(1byte) + チェックサム(2bytes)
36+
// command(1byte) + check sum(2bytes)
37+
int bytes = 3;
3738
for (int i = 0; i < segments.length; ++i)
3839
bytes += segments[i].length;
3940

4041
ByteBuffer buffer = ByteBuffer.allocate(bytes);
41-
buffer.put((byte) segments.length); // 個別部数
42-
for (int i = 0; i < segments.length; ++i) // 個別部
43-
buffer.put(segments[i]);
42+
buffer.put((byte) segments.length);
43+
for (int i = 0; i < segments.length; ++i) buffer.put(segments[i]);
4444

45-
int sum = segments.length; // チェックサム
45+
int sum = segments.length;
4646
for (int i = 0; i < segments.length; ++i) {
4747
byte[] e = segments[i];
4848
for (int j = 0; j < e.length; ++j) sum += e[j];
@@ -54,7 +54,7 @@ private static byte[] packSegment(byte[]... segments) {
5454

5555
private static byte[][] buildData(PushSegment segment) throws FeliCaException {
5656
try {
57-
return buildPushIntentSegment(1, "market://details?id=com.main.typograffit", "ANDR01");
57+
return buildPushIntentSegment(1, ((PushIntentSegment) segment).getIntentData().getData().toString(), "ANDR01");
5858
} catch (UnsupportedEncodingException e) {
5959
// TODO Auto-generated catch block
6060
e.printStackTrace();
@@ -65,22 +65,16 @@ private static byte[][] buildData(PushSegment segment) throws FeliCaException {
6565
private static byte[][] buildPushIntentSegment(int type, String url, String icc) throws UnsupportedEncodingException {
6666
byte[] urlBytes = url.getBytes(URL_CHARSET);
6767
byte[] iccBytes = icc.getBytes(ICC_CHARSET);
68-
69-
// type(1byte) + paramBytesLength(2bytes) + urlBytesLength(2bytes) + iccBytesLength(2bytes)
7068
int capacity = urlBytes.length + iccBytes.length + 7;
7169
ByteBuffer buffer = ByteBuffer.allocate(capacity);
7270

73-
// 個別部ヘッダ
74-
buffer.put((byte) type); // 起動制御情報
75-
int paramSize = capacity - 3; // 個別部パラメータサイズ: type(1byte) + paramBytesLength(2)
71+
buffer.put((byte) type);
72+
int paramSize = capacity - 3;
7673
putAsLittleEndian(paramSize, buffer);
77-
78-
// 個別部パラメータ
79-
putAsLittleEndian(0, buffer); // URLサイズ
80-
//buffer.put(urlBytes); // URL
81-
putAsLittleEndian(iccBytes.length, buffer); // iccサイズ
82-
buffer.put(iccBytes); // icc
83-
buffer.put(urlBytes); // (アプリケーション起動パラメータ)
74+
putAsLittleEndian(0, buffer);
75+
putAsLittleEndian(iccBytes.length, buffer);
76+
buffer.put(iccBytes);
77+
buffer.put(urlBytes);
8478
return new byte[][] { buffer.array() };
8579
}
8680

0 commit comments

Comments
 (0)