質問編集履歴
2
ko-dotuika
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,6 +92,68 @@
|
|
92
92
|
|
93
93
|
```
|
94
94
|
|
95
|
+
Manifest
|
96
|
+
|
97
|
+
```<?xml version="1.0" encoding="utf-8"?>
|
98
|
+
|
99
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
100
|
+
|
101
|
+
package="com.example.nfc_project"
|
102
|
+
|
103
|
+
android:versionCode="1"
|
104
|
+
|
105
|
+
android:versionName="1.0" >
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<uses-sdk
|
110
|
+
|
111
|
+
android:minSdkVersion="8"
|
112
|
+
|
113
|
+
android:targetSdkVersion="21" />
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
<application
|
118
|
+
|
119
|
+
android:allowBackup="true"
|
120
|
+
|
121
|
+
android:icon="@drawable/ic_launcher"
|
122
|
+
|
123
|
+
android:label="@string/app_name"
|
124
|
+
|
125
|
+
android:theme="@style/AppTheme" >
|
126
|
+
|
127
|
+
<activity
|
128
|
+
|
129
|
+
android:name=".MainActivity"
|
130
|
+
|
131
|
+
android:label="@string/app_name" >
|
132
|
+
|
133
|
+
<intent-filter>
|
134
|
+
|
135
|
+
<action android:name="android.intent.action.MAIN" />
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
140
|
+
|
141
|
+
</intent-filter>
|
142
|
+
|
143
|
+
</activity>
|
144
|
+
|
145
|
+
</application>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
</manifest>
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
95
157
|
|
96
158
|
|
97
159
|
###試したこと
|
1
ソースコード表示にしてなかった
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,79 +14,83 @@
|
|
14
14
|
|
15
15
|
###該当のソースコード
|
16
16
|
|
17
|
-
package com.example.nfc;
|
17
|
+
```package com.example.nfc;
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
import android.R;
|
21
|
+
import android.R;
|
22
22
|
|
23
|
-
import android.app.Activity;
|
23
|
+
import android.app.Activity;
|
24
24
|
|
25
|
-
import android.content.Intent;
|
25
|
+
import android.content.Intent;
|
26
26
|
|
27
|
-
import android.nfc.NfcAdapter;
|
27
|
+
import android.nfc.NfcAdapter;
|
28
28
|
|
29
|
-
import android.os.Bundle;
|
29
|
+
import android.os.Bundle;
|
30
30
|
|
31
31
|
import android.widget.TextView;
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
public class MainActivity extends Activity {
|
35
|
+
public class MainActivity extends Activity {
|
36
36
|
|
37
|
-
|
37
|
+
/** Called when the activity is first created. */
|
38
38
|
|
39
|
-
|
39
|
+
@Override
|
40
40
|
|
41
|
-
|
41
|
+
public void onCreate(Bundle savedInstanceState) {
|
42
42
|
|
43
|
-
|
43
|
+
super.onCreate(savedInstanceState);
|
44
44
|
|
45
|
-
|
45
|
+
setContentView(R.layout.activity_main);
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
|
49
|
+
Intent intent = getIntent();
|
50
50
|
|
51
|
-
|
51
|
+
String action = intent.getAction();
|
52
52
|
|
53
|
-
|
53
|
+
if(action.equals((NfcAdapter.ACTION_TECH_DISCOVERED))) {
|
54
54
|
|
55
|
-
|
55
|
+
byte[] rawId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
|
56
56
|
|
57
|
-
|
57
|
+
String text = bytesToText(rawId);
|
58
58
|
|
59
|
-
|
59
|
+
TextView nfcIdTextView = (TextView)findViewById(R.id.nfc_id_textview);
|
60
60
|
|
61
|
-
|
61
|
+
nfcIdTextView.setText(text);
|
62
62
|
|
63
|
-
|
63
|
+
}
|
64
64
|
|
65
|
-
|
65
|
+
}
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
|
69
|
+
private String bytesToText(byte[] bytes) {
|
70
70
|
|
71
|
-
|
71
|
+
StringBuilder buffer = new StringBuilder();
|
72
72
|
|
73
|
-
|
73
|
+
for (byte b : bytes) {
|
74
74
|
|
75
|
-
|
75
|
+
String hex = String.format("%02X", b);
|
76
76
|
|
77
|
-
|
77
|
+
buffer.append(hex).append(" ");
|
78
78
|
|
79
|
-
|
79
|
+
}
|
80
80
|
|
81
81
|
|
82
82
|
|
83
|
-
|
83
|
+
String text = buffer.toString().trim();
|
84
84
|
|
85
|
-
|
85
|
+
return text;
|
86
86
|
|
87
|
-
|
87
|
+
}
|
88
88
|
|
89
89
|
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```
|
90
94
|
|
91
95
|
|
92
96
|
|