diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9aa4026..226d02f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -5,7 +5,7 @@
android:versionName="1.0">
-
+
diff --git a/bin/ImageViewer.apk b/bin/ImageViewer.apk
new file mode 100644
index 0000000..5fe130e
Binary files /dev/null and b/bin/ImageViewer.apk differ
diff --git a/bin/classes.dex b/bin/classes.dex
new file mode 100644
index 0000000..ba3f287
Binary files /dev/null and b/bin/classes.dex differ
diff --git a/bin/com/nfc/demo/imageviewer/ImageViewer$1.class b/bin/com/nfc/demo/imageviewer/ImageViewer$1.class
new file mode 100644
index 0000000..98551f6
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/ImageViewer$1.class differ
diff --git a/bin/com/nfc/demo/imageviewer/ImageViewer.class b/bin/com/nfc/demo/imageviewer/ImageViewer.class
new file mode 100644
index 0000000..47f8732
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/ImageViewer.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R$attr.class b/bin/com/nfc/demo/imageviewer/R$attr.class
new file mode 100644
index 0000000..aa155cf
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R$attr.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R$drawable.class b/bin/com/nfc/demo/imageviewer/R$drawable.class
new file mode 100644
index 0000000..b1681a6
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R$drawable.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R$id.class b/bin/com/nfc/demo/imageviewer/R$id.class
new file mode 100644
index 0000000..b413350
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R$id.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R$layout.class b/bin/com/nfc/demo/imageviewer/R$layout.class
new file mode 100644
index 0000000..5ccc534
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R$layout.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R$string.class b/bin/com/nfc/demo/imageviewer/R$string.class
new file mode 100644
index 0000000..8dd407c
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R$string.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R$xml.class b/bin/com/nfc/demo/imageviewer/R$xml.class
new file mode 100644
index 0000000..f48900f
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R$xml.class differ
diff --git a/bin/com/nfc/demo/imageviewer/R.class b/bin/com/nfc/demo/imageviewer/R.class
new file mode 100644
index 0000000..ae0112c
Binary files /dev/null and b/bin/com/nfc/demo/imageviewer/R.class differ
diff --git a/bin/resources.ap_ b/bin/resources.ap_
new file mode 100644
index 0000000..6e64926
Binary files /dev/null and b/bin/resources.ap_ differ
diff --git a/gen/com/nfc/demo/imageviewer/R.java b/gen/com/nfc/demo/imageviewer/R.java
new file mode 100644
index 0000000..80936d5
--- /dev/null
+++ b/gen/com/nfc/demo/imageviewer/R.java
@@ -0,0 +1,46 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package com.nfc.demo.imageviewer;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int icon=0x7f020000;
+ public static final int icon_ipack=0x7f020001;
+ public static final int image1=0x7f020002;
+ public static final int image2=0x7f020003;
+ public static final int image3=0x7f020004;
+ public static final int image4=0x7f020005;
+ }
+ public static final class id {
+ public static final int block_0_data=0x7f060007;
+ public static final int block_0_label=0x7f060006;
+ public static final int clear_but=0x7f060008;
+ public static final int image1=0x7f060009;
+ public static final int image2=0x7f06000a;
+ public static final int image3=0x7f06000b;
+ public static final int image4=0x7f06000c;
+ public static final int purchScanES1=0x7f060004;
+ public static final int purchScanTable1=0x7f060000;
+ public static final int status_data=0x7f060003;
+ public static final int status_label=0x7f060002;
+ public static final int table1Row1=0x7f060001;
+ public static final int table1Row2=0x7f060005;
+ }
+ public static final class layout {
+ public static final int main=0x7f030000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f050001;
+ public static final int hello=0x7f050000;
+ }
+ public static final class xml {
+ public static final int filter_nfc=0x7f040000;
+ }
+}
diff --git a/res/drawable-mdpi/image1.JPG b/res/drawable-mdpi/image1.JPG
deleted file mode 100644
index 27492bf..0000000
Binary files a/res/drawable-mdpi/image1.JPG and /dev/null differ
diff --git a/res/drawable-mdpi/image1.jpg b/res/drawable-mdpi/image1.jpg
new file mode 100644
index 0000000..594c96d
Binary files /dev/null and b/res/drawable-mdpi/image1.jpg differ
diff --git a/res/drawable-mdpi/image2.JPG b/res/drawable-mdpi/image2.JPG
deleted file mode 100644
index 0033daa..0000000
Binary files a/res/drawable-mdpi/image2.JPG and /dev/null differ
diff --git a/res/drawable-mdpi/image2.jpg b/res/drawable-mdpi/image2.jpg
new file mode 100644
index 0000000..b5c54c2
Binary files /dev/null and b/res/drawable-mdpi/image2.jpg differ
diff --git a/res/drawable-mdpi/image3.jpg b/res/drawable-mdpi/image3.jpg
index 4698b5c..33c3cc0 100644
Binary files a/res/drawable-mdpi/image3.jpg and b/res/drawable-mdpi/image3.jpg differ
diff --git a/res/drawable-mdpi/image4.jpg b/res/drawable-mdpi/image4.jpg
index ba1ceab..8e2ef90 100644
Binary files a/res/drawable-mdpi/image4.jpg and b/res/drawable-mdpi/image4.jpg differ
diff --git a/res/drawable-mdpi/image5.jpg b/res/drawable-mdpi/image5.jpg
new file mode 100644
index 0000000..6144c1d
Binary files /dev/null and b/res/drawable-mdpi/image5.jpg differ
diff --git a/res/drawable-mdpi/image6.jpg b/res/drawable-mdpi/image6.jpg
new file mode 100644
index 0000000..7e14055
Binary files /dev/null and b/res/drawable-mdpi/image6.jpg differ
diff --git a/res/layout/main.xml b/res/layout/main.xml
index ebad120..b415206 100644
--- a/res/layout/main.xml
+++ b/res/layout/main.xml
@@ -1,88 +1,64 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="@string/app_name">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/nfc/demo/imageviewer/ImageViewer.java b/src/com/nfc/demo/imageviewer/ImageViewer.java
index 1b818c7..8c4eb44 100644
--- a/src/com/nfc/demo/imageviewer/ImageViewer.java
+++ b/src/com/nfc/demo/imageviewer/ImageViewer.java
@@ -2,10 +2,12 @@
* Written by Hesham Omran, heshamo@kth.se
* Edited from :
http://mifareclassicdetectiononandroid.blogspot.com/2011/04/reading-mifare-classic-1k-from-android.html
-*/
+ */
package com.nfc.demo.imageviewer;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import android.app.Activity;
import android.app.AlertDialog;
@@ -14,6 +16,9 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.MifareClassic;
@@ -24,294 +29,229 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
-
+
public class ImageViewer extends Activity implements OnClickListener {
- // UI Elements
- private static TextView block_0_Data;
- private static TextView status_Data;
-
- //image view controls
- private int gone = 0x00000008;
- private int visible = 0x00000000;
- private int invisible = 0x00000004;
-
- private int IV1 = visible;
- private int IV2 = gone;
- private int IV3 = gone;
- private int IV4 = gone;
-
- // NFC parts
- private static NfcAdapter mAdapter;
- private static PendingIntent mPendingIntent;
- private static IntentFilter[] mFilters;
- private static String[][] mTechLists;
- // Hex help
- private static final byte[] HEX_CHAR_TABLE = { (byte) '0', (byte) '1',
- (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6',
- (byte) '7', (byte) '8', (byte) '9', (byte) 'A', (byte) 'B',
- (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F' };
- // Just for alerts
- //Mifare application directory keyA
- //public static final byte[] UID1 = {(byte) 0xDB, (byte) 0xAE, (byte) 0xD8, (byte) 0xE9};
-
- String UID1 = "DBAED8E9";
- String UID2 = "1BAFD8E9";
- String UID3 = "FBE4DDE9";
- String UID4 = "BBE4DDE9";
-
- public static final byte[] KEY_MIFARE_APPLICATION_DIRECTORY = {
- (byte) 0xA0, (byte) 0xA1, (byte) 0xA2, (byte) 0xA3,
- (byte) 0xA4, (byte) 0xA5 };
- //NFC Forum default keyA
- public static final byte[] KEY_NFC_FORUM = { (byte) 0xD3,
- (byte) 0xF7, (byte) 0xD3, (byte) 0xF7, (byte) 0xD3,
- (byte) 0xF7 };
- private static final int AUTH = 1;
- private static final int EMPTY_BLOCK_0 = 2;
-
- private static final int NETWORK = 4;
- private static final String TAG = "purchtagscanact";
- public static final byte[] NXP_APP_KEYA = {(byte)'A'};
-
- /** Called when the activity is first created. */
- @Override
-
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- ImageView image1 = (ImageView) findViewById(R.id.image1);
- ImageView image2 = (ImageView) findViewById(R.id.image2);
- ImageView image3 = (ImageView) findViewById(R.id.image3);
- ImageView image4 = (ImageView) findViewById(R.id.image4);
- //integer value of image visibility
- int gone = 0x00000008;
- int visible = 0x00000000;
- int invisible = 0x00000004;
-
- //add indiv image views
-
- //Set all images to be GONE initially
- image1.setVisibility(IV1);
- image2.setVisibility(IV2);
- image3.setVisibility(IV3);
- image4.setVisibility(IV4);
-
- block_0_Data = (TextView) findViewById(R.id.block_0_data);
- status_Data = (TextView) findViewById(R.id.status_data);
- // Capture Purchase button from layout
- Button scanBut = (Button) findViewById(R.id.clear_but);
- // Register the onClick listener with the implementation above
- scanBut.setOnClickListener(this);
- // Register the onClick listener with the implementation above
- scanBut.setOnClickListener(this);
- mAdapter = NfcAdapter.getDefaultAdapter(this);
- // Create a generic PendingIntent that will be deliver to this activity.
- // The NFC stack
- // will fill in the intent with the details of the discovered tag before
- // delivering to
- // this activity.
- mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
- getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
- // Setup an intent filter for all MIME based dispatches
- IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
- try {
- ndef.addDataType("*/*");
- } catch (MalformedMimeTypeException e) {
- throw new RuntimeException("fail", e);
- }
- mFilters = new IntentFilter[] { ndef, };
- // Setup a tech list for all NfcF tags
- mTechLists = new String[][] { new String[] { MifareClassic.class
- .getName() } };
- Intent intent = getIntent();
- String cardData= null;
- resolveIntent(intent);
- }
- void resolveIntent(Intent intent) {
- // Parse the intent
- String action = intent.getAction();
- String myUID = null;
- if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
- // status_Data.setText("Discovered tag with intent: " + intent);
- Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
- MifareClassic mfc = MifareClassic.get(tagFromIntent);
- byte[] data;
- try {
- mfc.connect();
- boolean auth = false;
- String cardData = null;
- status_Data.setText("Authenticating the Tag..");
- // Authenticating and reading Block 0 /Sector 1
- auth = mfc.authenticateSectorWithKeyA(0,
- MifareClassic.KEY_DEFAULT);
- if (auth) {
- data = mfc.readBlock(0);
- //cardData = getHexString(data, data.length);
- cardData=getHexString(data,4);
- if (cardData != null) {
- block_0_Data.setText(cardData);
- } else {
- showAlert(EMPTY_BLOCK_0);
- }
- }
- else {
- auth = mfc.authenticateSectorWithKeyA(0,
- MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY);
- if (auth) {
- data = mfc.readBlock(0);
- //cardData = getHexString(data, data.length); fix it to UID size
- cardData=getHexString(data,4);
- myUID=getHexString(data,4);
- if (cardData != null) {
- block_0_Data.setText(cardData);
- }
- else {
- showAlert(EMPTY_BLOCK_0);
- }
- }
- else{
- showAlert(AUTH);
- }
- }
- } catch (IOException e) {
- Log.e(TAG, e.getLocalizedMessage());
- showAlert(NETWORK);
- }
- } else {
- status_Data.setText("Online + Scan a tag");
- }
- //image2.setVisibility(gone);
-
- imageDisp(myUID);
-
- }
+ // UI Elements
+ private static TextView block_0_Data;
+ private static TextView status_Data;
+
+ // NFC parts
+ private static NfcAdapter mAdapter;
+ private static PendingIntent mPendingIntent;
+ private static IntentFilter[] mFilters;
+ private static String[][] mTechLists;
+
+ // Hex help
+ private static final byte[] HEX_CHAR_TABLE = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4',
+ (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D',
+ (byte) 'E', (byte) 'F' };
+
+ // Just for alerts
+ // Mifare application directory keyA
+ // public static final byte[] UID1 = {(byte) 0xDB, (byte) 0xAE, (byte) 0xD8,
+ // (byte) 0xE9};
+
+ /* hardcoded strings we have in a hash*/
+ public Map mHash = new HashMap();
- private void showAlert(int alertCase) {
- // prepare the alert box
- AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
- switch (alertCase) {
+ public static final byte[] KEY_MIFARE_APPLICATION_DIRECTORY = { (byte) 0xA0, (byte) 0xA1, (byte) 0xA2, (byte) 0xA3,
+ (byte) 0xA4, (byte) 0xA5 };
+ // NFC Forum default keyA
+ public static final byte[] KEY_NFC_FORUM = { (byte) 0xD3, (byte) 0xF7, (byte) 0xD3, (byte) 0xF7, (byte) 0xD3,
+ (byte) 0xF7 };
+ private static final int AUTH = 1;
+ private static final int EMPTY_BLOCK_0 = 2;
- case AUTH:// Card Authentication Error
- alertbox.setMessage("Authentication Failed on Block 0");
- break;
- case EMPTY_BLOCK_0: // Block 0 Empty
- alertbox.setMessage("Failed reading Block 0");
- break;
- case NETWORK: // Communication Error
- alertbox.setMessage("Tag reading error");
- break;
- }
- // set a positive/yes button and create a listener
- alertbox.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ private static final int NETWORK = 4;
+ private static final String TAG = "purchtagscanact";
+ public static final byte[] NXP_APP_KEYA = { (byte) 'A' };
- // Save the data from the UI to the database - already done
- public void onClick(DialogInterface arg0, int arg1) {
- clearFields();
- }
- });
- // display box
- alertbox.show();
- }
-
- public void imageDisp(String x){
- IV1=gone;
- IV2=gone;
- IV3=visible;
- IV4=gone;
-
- ImageView image1 = (ImageView) findViewById(R.id.image1);
- ImageView image2 = (ImageView) findViewById(R.id.image2);
- ImageView image3 = (ImageView) findViewById(R.id.image3);
- ImageView image4 = (ImageView) findViewById(R.id.image4);
-
- image1.setVisibility(IV1);
- image2.setVisibility(IV2);
- image3.setVisibility(IV3);
- image4.setVisibility(IV4);
+ private ImageView image;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
- if(UID1.equals(x))
- {
- image1.setVisibility(visible);
- image2.setVisibility(gone);
- image3.setVisibility(gone);
- image4.setVisibility(gone);
- }
- else if (UID2.equals(x))
- {
- image1.setVisibility(gone);
- image2.setVisibility(visible);
- image3.setVisibility(gone);
- image4.setVisibility(gone);
+ // Fill in the hash with tags and images
+ mHash.put("0478578A", R.drawable.image1);
+ mHash.put("0496578A", R.drawable.image2);
+ mHash.put("0495578A", R.drawable.image3);
+ mHash.put("0485578A", R.drawable.image4);
+ mHash.put("0486578A", R.drawable.image5);
+ mHash.put("04112F9A", R.drawable.image6);
+
+ image = (ImageView) findViewById(R.id.image);
+ Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
+ BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
+ image.setImageDrawable(bitmapDrawable);
+
+ block_0_Data = (TextView) findViewById(R.id.block_0_data);
+ status_Data = (TextView) findViewById(R.id.status_data);
+
+ // Capture Purchase button from layout
+ Button scanBut = (Button) findViewById(R.id.clear_but);
+ // Register the onClick listener with the implementation above
+ scanBut.setOnClickListener(this);
+ // Register the onClick listener with the implementation above
+ scanBut.setOnClickListener(this);
+ mAdapter = NfcAdapter.getDefaultAdapter(this);
+
+ // Create a generic PendingIntent that will be deliver to this activity.
+ // The NFC stack
+ // will fill in the intent with the details of the discovered tag before
+ // delivering to
+ // this activity.
+ mPendingIntent = PendingIntent.getActivity(this, 0,
+ new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
+ // Setup an intent filter for all MIME based dispatches
+ IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
+ try {
+ ndef.addDataType("*/*");
+ } catch (MalformedMimeTypeException e) {
+ throw new RuntimeException("fail", e);
}
- else if (UID3.equals(x))
- {
- image1.setVisibility(gone);
- image2.setVisibility(gone);
- image3.setVisibility(visible);
- image4.setVisibility(gone);
+ mFilters = new IntentFilter[] { ndef, };
+ // Setup a tech list for all NfcF tags
+ mTechLists = new String[][] { new String[] { MifareClassic.class.getName() } };
+ Intent intent = getIntent();
+
+ resolveIntent(intent);
+ }
+
+ void resolveIntent(Intent intent) {
+ // Parse the intent
+ String action = intent.getAction();
+ String myUID = null;
+ if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
+ // status_Data.setText("Discovered tag with intent: " + intent);
+ Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
+ MifareClassic mfc = MifareClassic.get(tagFromIntent);
+ byte[] data;
+ try {
+ mfc.connect();
+ boolean auth = false;
+ String cardData = null;
+ status_Data.setText("Authenticating the Tag..");
+ // Authenticating and reading Block 0 /Sector 1
+ auth = mfc.authenticateSectorWithKeyA(0, MifareClassic.KEY_DEFAULT);
+ if (auth) {
+ data = mfc.readBlock(0);
+ // cardData = getHexString(data, data.length);
+ cardData = getHexString(data, 4);
+ if (cardData != null) {
+ block_0_Data.setText(cardData);
+ myUID = cardData;
+ } else {
+ showAlert(EMPTY_BLOCK_0);
+ }
+ } else {
+ auth = mfc.authenticateSectorWithKeyA(0, MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY);
+ if (auth) {
+ data = mfc.readBlock(0);
+ // cardData = getHexString(data, data.length); fix it to
+ // UID size
+ cardData = getHexString(data, 4);
+ myUID = getHexString(data, 4);
+ if (cardData != null) {
+ block_0_Data.setText(cardData);
+ } else {
+ showAlert(EMPTY_BLOCK_0);
+ }
+ } else {
+ showAlert(AUTH);
+ }
+ }
+ } catch (IOException e) {
+ Log.e(TAG, e.getLocalizedMessage());
+ showAlert(NETWORK);
+ }
+ } else {
+ status_Data.setText("Online + Scan a tag");
}
- else if (UID4.equals(x))
- {
- image1.setVisibility(gone);
- image2.setVisibility(gone);
- image3.setVisibility(gone);
- image4.setVisibility(visible);
+
+ imageDisp(myUID);
+ }
+
+ private void showAlert(int alertCase) {
+ // prepare the alert box
+ AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
+ switch (alertCase) {
+
+ case AUTH:// Card Authentication Error
+ alertbox.setMessage("Authentication Failed on Block 0");
+ break;
+ case EMPTY_BLOCK_0: // Block 0 Empty
+ alertbox.setMessage("Failed reading Block 0");
+ break;
+ case NETWORK: // Communication Error
+ alertbox.setMessage("Tag reading error");
+ break;
}
- else
- {
- image1.setVisibility(gone);
- image2.setVisibility(gone);
- image3.setVisibility(gone);
- image4.setVisibility(gone);
+
+ // set a positive/yes button and create a listener
+ alertbox.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ // Save the data from the UI to the database - already done
+ public void onClick(DialogInterface arg0, int arg1) {
+ clearFields();
+ }
+ });
+
+ alertbox.show();
+ }
+
+ public void imageDisp(String x) {
+ if ( mHash.containsKey(x) ) {
+ Bitmap bmp = BitmapFactory.decodeResource( getResources(), mHash.get(x) );
+ BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
+ image.setImageDrawable(bitmapDrawable);
}
- }
+ }
- @Override
- public void onClick(View v) {
- clearFields();
- }
+ @Override
+ public void onClick(View v) {
+ clearFields();
+ }
- private static void clearFields() {
- block_0_Data.setText("");
- status_Data.setText("Ready for Scan");
- }
+ private static void clearFields() {
+ block_0_Data.setText("");
+ status_Data.setText("Ready for Scan");
+ }
- public static String getHexString(byte[] raw, int len) {
- byte[] hex = new byte[2 * len];
- int index = 0;
- int pos = 0;
+ public static String getHexString(byte[] raw, int len) {
+ byte[] hex = new byte[2 * len];
+ int index = 0;
+ int pos = 0;
- for (byte b : raw) {
- if (pos >= len)
- break;
+ for (byte b : raw) {
+ if (pos >= len)
+ break;
- pos++;
- int v = b & 0xFF;
- hex[index++] = HEX_CHAR_TABLE[v >>> 4];
- hex[index++] = HEX_CHAR_TABLE[v & 0xF];
- }
+ pos++;
+ int v = b & 0xFF;
+ hex[index++] = HEX_CHAR_TABLE[v >>> 4];
+ hex[index++] = HEX_CHAR_TABLE[v & 0xF];
+ }
- return new String(hex);
- }
+ return new String(hex);
+ }
- @Override
- public void onResume() {
- super.onResume();
- mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters,
- mTechLists);
- }
+ @Override
+ public void onResume() {
+ super.onResume();
+ mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
+ }
- @Override
- public void onNewIntent(Intent intent) {
- Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);
- resolveIntent(intent);
- // mText.setText("Discovered tag " + ++mCount + " with intent: " +
- // intent);
- }
+ @Override
+ public void onNewIntent(Intent intent) {
+ Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);
+ resolveIntent(intent);
+ }
- @Override
- public void onPause() {
- super.onPause();
- mAdapter.disableForegroundDispatch(this);
- }
+ @Override
+ public void onPause() {
+ super.onPause();
+ mAdapter.disableForegroundDispatch(this);
+ }
}
\ No newline at end of file