Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8 from jonreeve/nfc_uri_prefix_fix

Fixed buildUrlBytes so it would select a longer prefix
  • Loading branch information...
commit d39343073585981ed593277e540d9161c53f7b2c 2 parents e0d2dde + 2e92145
@commonsguy authored
Showing with 15 additions and 15 deletions.
  1. +15 −15 NFC/URLTagger/src/com/commonsware/android/nfc/url/URLTagger.java
View
30 NFC/URLTagger/src/com/commonsware/android/nfc/url/URLTagger.java
@@ -68,7 +68,7 @@ protected void onNewIntent(Intent intent) {
if (inWriteMode &&
NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Tag tag=intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
- byte[] url=buildUrlBytes();
+ byte[] url=buildUrlBytes(intent.getStringExtra(Intent.EXTRA_TEXT));
NdefRecord record=new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
NdefRecord.RTD_URI,
new byte[] {}, url);
@@ -105,29 +105,29 @@ public void onPause() {
super.onPause();
}
- private byte[] buildUrlBytes() {
- String raw=getIntent().getStringExtra(Intent.EXTRA_TEXT);
- int prefix=0;
- String subset=raw;
+ private byte[] buildUrlBytes(String url) {
+ byte prefixByte=0;
+ String subset=url;
+ int bestPrefixLength=0;
for (int i=0;i<PREFIXES.length;i++) {
- if (raw.startsWith(PREFIXES[i])) {
- prefix=i+1;
- subset=raw.substring(PREFIXES[i].length());
-
- break;
+ String prefix = PREFIXES[i];
+ if (url.startsWith(prefix) && prefix.length() > bestPrefixLength) {
+ prefixByte=(byte)(i+1);
+ bestPrefixLength=prefix.length();
+ subset=url.substring(bestPrefixLength);
}
}
- byte[] subsetBytes=subset.getBytes();
- byte[] result=new byte[subsetBytes.length+1];
+ final byte[] subsetBytes = subset.getBytes();
+ final byte[] result = new byte[subsetBytes.length+1];
- result[0]=(byte)prefix;
+ result[0]=prefixByte;
System.arraycopy(subsetBytes, 0, result, 1, subsetBytes.length);
return(result);
}
-
+
static class WriteTask extends AsyncTask<Void, Void, Void> {
Activity host=null;
NdefMessage msg=null;
@@ -211,4 +211,4 @@ protected void onPostExecute(Void unused) {
host.finish();
}
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.