Monday, August 08, 2016

Android: BLOB (PHP) to Android (Java)

Image stored as BLOB in mysql.

To load image in android:
  1. Encode image binary data with base64. $obj->picture = base64_encode($binaryData);
  2. Encode in json. json_encode($obj)
  3. Receive data in android
  4. Get byte[] using Base64.decode.
  5. Get bitmap .Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 

          byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);

Monday, August 01, 2016

Android: Adding header info when fetching or sending data to server-side script

With reference to previous video on fetching and posting data from/to the web.
Example: 
conn.setDoOutput(true); // POST
// prepare headers
conn.setRequestProperty("X-Parse-Application-Id", /*** your parse app id in parse.com ***/);
conn.setRequestProperty("X-Parse-REST-API-Key", /*** your parse REST API key in parse.com ***/);
conn.setRequestProperty("Content-Type", "application/json");

Android: Adding header info when fetching or sending data to server-side script

With reference to previous video on fetching and posting data from/to the web.
Example: 
conn.setDoOutput(true); // POST
// prepare headers
conn.setRequestProperty("X-Parse-Application-Id", /*** your parse app id in parse.com ***/);
conn.setRequestProperty("X-Parse-REST-API-Key", /*** your parse REST API key in parse.com ***/);
conn.setRequestProperty("Content-Type", "application/json");

Android: Adding header info when fetching or sending data to server-side script

With reference to previous video on fetching and posting data from/to the web.
Example: 
conn.setDoOutput(true); // POST
// prepare headers
conn.setRequestProperty("X-Parse-Application-Id", /*** your parse app id in parse.com ***/);
conn.setRequestProperty("X-Parse-REST-API-Key", /*** your parse REST API key in parse.com ***/);
conn.setRequestProperty("Content-Type", "application/json");

Android: WebView

WebView demo to display HTML page in Activity and to enable Javascript


Adding Javascript interface to WebView to allow Javascript to communicate with and use Java classes

Android: SQLite database and ListView

Reading data from SQLite database and using it in ListView

Android: SQLite Databases

Create a SQLite database


Insert data into database table


Delete data in database table


Update data in database table


Reading data from database table and using a loop to process the data retrieved



Android: posting data to server side script

Posting data to PHP script


Using StringBuilder to format the data string to prepare to send to server side

Android: parsing XML and JSON

Parsing XML content


sample XML data:
<channel>
<title>Singapore - Nowcast and Forecast</title>
<description>3 hour Forecast</description>
<item>
<title>Nowcast Table</title>
<category>Singapore Weather Conditions</category>
<weatherForecast>
<area name="ANG MO KIO" forecast="Partly cloudy " icon="PC" zone="C" lat="1.37000000" lon="103.84940000"/>
<area name="BEDOK" forecast="Partly cloudy " icon="PC" zone="E" lat="1.32403830" lon="103.92003560"/>
<area name="BISHAN" forecast="Partly cloudy " icon="PC" zone="C" lat="1.35120000" lon="103.84850000"/>
<area name="BUKIT BATOK" forecast="Partly cloudy " icon="PC" zone="W" lat="1.34910000" lon="103.74970000"/>
<area name="BUKIT PANJANG" forecast="Showers " icon="SH" zone="C" lat="1.38080000" lon="103.76250000"/>
</weatherForecast>
</item>

</channel>

Parsing JSON


Sample JSON data: 
{"coord":{"lon":103.85,"lat":1.29},"weather":[{"id":803, "main":"Clouds", "description":"broken clouds", "icon":"04d"}],"base":"cmc stations","main":{"temp":31.97, "pressure":1010, "humidity":63, "temp_min":31, "temp_max":33},"wind":{"speed":5.7,"deg":80},"clouds":{"all":75}, "dt":1451979432, "sys": {"type":1, "id":8143, "message":0.0033, "country":"SG", "sunrise":1451948892, "sunset":1451992281},"id":1880252,"name":"Singapore","cod":200}

Android: getting and reading online content


Setting up: XML, manifest


Fetching the content from URL using a background task


Reading the fetched content using Stream readers.

Android: Threading, Asynchronous Tasks

Create an AsyncTask to perform a task running in the background

Android videos: Activity, Button, onClick

How to create a new Activity in android studio

Create a button and make it do something when clicked

How to go to a new Activity when a button is clicked

jQuery videos: HTML forms, jQuery and PHP

Form submission


Reading JSON from PHP 

Reading HTML from PHP


Send data to PHP