Note that there are some explanatory texts on larger screens.

plurals
  1. POIllegal character in NDEF URI payload
    primarykey
    data
    text
    <p>I'm writing NFC based app that would scan a NFC tag with a Url. Once, the tag is scanned, the app should retrieve information from a database and display it in a ListView. </p> <p>The error occurs when I scan the NFC tag. </p> <pre><code> Error in http connection java.lang.IllegalArgumentException: Illegal character in scheme at index 0: ??http://abc.com/~090123/get_items.php </code></pre> <p>The logcat displays some weird <code>??</code> characters before <code>http://</code>. </p> <p>I'm writing the Url in the tag using following code:</p> <pre><code>private boolean writeTag(Tag tag) { byte[] uriField = "http://abc.com/~090123/get_items.php".getBytes(Charset.forName("US-ASCII")); byte[] payload = new byte[uriField.length + 1]; System.arraycopy(uriField, 0, payload, 1, uriField.length); NdefRecord uriRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], payload); NdefMessage message = new NdefMessage(new NdefRecord[] { uriRecord}); // .... } </code></pre> <p>I'm receiving intent from the NFC tag like this:</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_display); Intent intent = getIntent(); if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra( NfcAdapter.EXTRA_NDEF_MESSAGES); if(rawMsgs != null) { NdefMessage msg = (NdefMessage) rawMsgs[0]; GetData getData = new GetData(this); getData.execute(new String(msg.getRecords()[0].getPayload())); } } } </code></pre> <p>And I'm retrieving information from database using the following code:</p> <pre><code>protected BufferedReader doInBackground(String... params) { ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); try { HttpClient httpclient = new DefaultHttpClient(); for (int i = 0; i &lt; params.length; i++) { HttpPost httppost = new HttpPost(params[i]); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } Log.e("Input Stream", "Input Stream:" + is); BufferedReader myReader = new BufferedReader(new InputStreamReader(is)); return myReader; } </code></pre> <p>I have the intent filter for the previous NDEF records like this:</p> <pre><code>&lt;activity android:name=".DisplayContentActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.nfc.action.NDEF_DISCOVERED" /&gt; &lt;data android:host="abc.com" android:pathPrefix="/~090123/get_items.php" android:scheme="http" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p>Any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload