-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/java/ceui/lisa/activities/NfcDemoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ceui.lisa.activities; | ||
|
||
import android.app.PendingIntent; | ||
import android.content.Intent; | ||
import android.nfc.NfcAdapter; | ||
import android.nfc.Tag; | ||
|
||
import ceui.lisa.R; | ||
import ceui.lisa.base.BaseActivity; | ||
import ceui.lisa.databinding.ActivityNfcBinding; | ||
import ceui.lisa.utils.Common; | ||
|
||
public class NfcDemoActivity extends BaseActivity<ActivityNfcBinding> { | ||
|
||
private NfcAdapter mNfcAdapter; | ||
private PendingIntent pi; | ||
|
||
@Override | ||
protected int initLayout() { | ||
return R.layout.activity_nfc; | ||
} | ||
|
||
@Override | ||
protected void initView() { | ||
mNfcAdapter = NfcAdapter.getDefaultAdapter(this); | ||
|
||
pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass()) | ||
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); | ||
processIntent(getIntent()); | ||
} | ||
|
||
@Override | ||
protected void initData() { | ||
|
||
} | ||
|
||
@Override | ||
protected void onNewIntent(Intent intent) { | ||
super.onNewIntent(intent); | ||
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { | ||
processIntent(intent); | ||
} | ||
} | ||
|
||
private void processIntent(Intent intent) { | ||
//取出封装在intent中的TAG | ||
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); | ||
String CardId =ByteArrayToHexString(tagFromIntent.getId()); | ||
Common.showLog("CardId " + tagFromIntent.toString()); | ||
Common.showLog("intent " + intent.toString()); | ||
} | ||
|
||
private String ByteArrayToHexString(byte[] inarray) { | ||
int i, j, in; | ||
String[] hex = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", | ||
"B", "C", "D", "E", "F" }; | ||
String out = ""; | ||
|
||
|
||
for (j = 0; j < inarray.length; ++j) { | ||
in = (int) inarray[j] & 0xff; | ||
i = (in >> 4) & 0x0f; | ||
out += hex[i]; | ||
i = in & 0x0f; | ||
out += hex[i]; | ||
} | ||
return out; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.qmuiteam.qmui.widget.QMUIVerticalTextView | ||
android:layout_width="wrap_content" | ||
android:text="NFC" | ||
android:textSize="100sp" | ||
android:layout_centerInParent="true" | ||
android:layout_height="wrap_content"> | ||
|
||
|
||
</com.qmuiteam.qmui.widget.QMUIVerticalTextView> | ||
|
||
</RelativeLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | ||
<tech-list> | ||
<tech>android.nfc.tech.IsoDep</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.NfcA</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.NfcB</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.NfcF</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.NfcV</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.Ndef</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.NdefFormatable</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.MifareClassic</tech> | ||
</tech-list> | ||
<tech-list> | ||
<tech>android.nfc.tech.MifareUltralight</tech> | ||
</tech-list> | ||
</resources> |