Monday, 25 November 2013

View the Android App database contents

So you created your Android App with SQLite database, and you are interested to view the database offline. You can do it with the adb command.

1) in command line, issue "adb shell" command, and then you will go to android prompt:
root@android:/ #

2) cd data/data, then ls, and you will see a lot of the App package:

3) cd  to your App package, say for example "com.victor.example"

4) cd databases, and ls to find out the databases name

5) run the command "sqlite3 mydb.s3db"
root@android:/data/data/com.victor.example/databases # sqlite3 mydb.s3db
sqlite3 mydb.s3db
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

6) check the table name
sqlite> .tables
android_metadata  employees
sqlite> select * from employees;
select * from employees;

7) That's it. You successfully view the App database content using the adb shell command.

Sunday, 24 November 2013

Export Excel data to MySQL database

We will show you how to export Excel data to MySQL db.

The steps are:

1) saved the excel data to csv format, such as below
BK001,Introduction to science,976,85.0
BK002,Human Anatomy,985,200.0
BK003,Concepts in Health,765,100.5

2) create a db table that matches the csv format
mysql> create table book_info
    -> (book_id varchar(20), book_name varchar(40), isbn_no int(11), book_price, int(10));

3) run the mysql command
mysql> load data infile 'c:\\Book1.csv' into table book_info fields terminated by ',' lines terminated by '\n';
Query OK, 3 rows affected (0.07 sec)
Records: 3  Deleted: 0  Skipped: 0  Warnings: 0

After that, the db contains the Excel data, To verify, issue the command:

mysql> select * from book_info;
| book_id | book_name               | isbn_no | book_price |
| BK001   | Introduction to science |     976 |         85 |
| BK002   | Human Anatomy           |     985 |        200 |
| BK003   | Concepts in Health      |     765 |        101 |
3 rows in set (0.00 sec)

Friday, 25 October 2013

Facebook App Development on Android

On Facebook
Firstly, we talk about the tasks and tools available on Facebook developers.

Now, login to your FB account, go to "Manage Apps"

Choose "Edit App" or "Create New App".

Here are the basic settings of the App:

Then, choose "Use Graph API Explorer".
Enter the POST action path: "me/victory-test-now:gin"

victory-test-now is the namespace, gin is the Action. You may have to add the Action in the "Open Graph" section beforehand.

The food url is from "Open Graph->Types":

After clicking submit button in the Graph API Explorer, go to the Activity Log of the user. You can see the Action in the Activity Log.

You can add a place field to the POST Action.

The place id can be obtained using the following method.

Click on the profile picture, right click, choose "Copy link address"

For example, the link address is below.

The place id is "145768288146".

The Action can be seen in the Activity Log again.

On Android
Secondly, we highlight how the Android App is able to access the data in Facebook through the Facebook App.

Preparation steps:

  • Download the Facebook SDK for Android
  • Import the SDK into Eclipse
  • Compile and build it

After that, you can start to create an Android App in Eclipse. The good tutorial from FB is listed below:

After you have created the Android App, we go back to the App Dashboard on Facebook Developers, and register the Android package and activity name in the "Native Android App" settings. As an example, the detail info is shown below.

To get the Key Hash, add the code to the OnCreate() method of the MainActivity class.
    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

Publish to Facebook Feed

In the Facebook tutorial below,
it talks about publishing to Open Graph story.

You could modify the code to make it publish to Facebook Feed. Sounds interesting, isn't it? The essential changes are:

1) populate the Bundle with the description, link, name, caption
2) change the post action path to "me/feed"

The obvious changes are not difficult. However, you may have to retrieve the user info from List<GraphUser>.

                        public String announceString;
                        private List<GraphUser> selectedUsers;
                     for (GraphUser user : selectedUsers) {
                         announceString += user.getName();

The changes to AsyncTask:

AsyncTask<Void, Void, Response> task =
    new AsyncTask<Void, Void, Response>() {

    protected Response doInBackground(Void... voids) {
        // Create an eat action
        EatAction eatAction =
        // Populate the action with the POST parameters:
        // the meal, friends, and place info
        for (BaseListElement element : listElements) {
        // Set up a request with the active session, set up
        // an HTTP POST to the eat action endpoint
         // Request request = new Request(Session.getActiveSession(),
         //         POST_ACTION_PATH, null, HttpMethod.POST);
        Bundle postParams = new Bundle();
        postParams.putString("name", "Gin food");
        postParams.putString("caption", "Gin food");
        postParams.putString("description", announceString);
        postParams.putString("link", announceUrl);
        Request request = new Request(Session.getActiveSession(),
        "me/feed", postParams, HttpMethod.POST);
        // Add the post parameter, the eat action
        // Execute the request synchronously in the background
        // and return the response.
        return request.executeAndWait();

    protected void onPostExecute(Response response) {
        // When the task completes, process
        // the response on the main thread

Tuesday, 22 October 2013

Factory Design Pattern

The factory design pattern is a pattern that has some methods that create objects for you. You don't use new method directly to create the objects. 

When you want to change the types of objects created, you just change the factory. All other codes that use the factory change automatically.

For example, in PHP:


class ClassModelC {
  private $ModelC;  
  public function __construct($c)
    $this->ModelC = $c;
  public function getModel()
  {  return $this->ModelC; }
class ClassModelB {
  private $ModelB;
  public function __construct($b)
    $this->ModelB = $b;
  public function getModel()
  {  return $this->ModelB; }

class ClassModelA {
  private $ModelA;
  public function __construct($b, $c)
    $this->ModelA = $b->getModel().' '.$c->getModel();
  public function getModel()
    return $this->ModelA;

class Factory{
    public function build($b, $c)
        $classc = $this->buildC($c);
        $classb = $this->buildB($b);
        return $this->buildA($classb, $classc);

    public function buildA($classb, $classc)
        return new ClassModelA($classb, $classc);

    public function buildB($b)
        return new ClassModelB($b);

    public function buildC($c)
        return new ClassModelC($c);

$factory = new Factory;
$obj     = $factory->build('Thunderbird','Jaguar');

If in future, you want to change the object type, you can just change the factory method, as below.

class Factory_New extends Factory{
    public function build($b, $c)
        return DatabaseObject($b, $c);

Monday, 21 October 2013

Espana, Siempre Pienso En Ti


After a 12 hour stop over at Doha, and another 7 hour flight time, i arrived at Barcelona at 7am local time.

early morning at Passeig de Gracia, the main thoroughfare of BCN
a section of the Barcelona city
looking at the La Sagrada Familia from afar
the ceilings of La Sagrada Familia
the metro station of Sagrada Famalia
The magic chimney of Casa Mira
Shopping Mall at Port Vell

The province of Andalucia is famous for its distinctive architecture, and remains of its Moorish occupation.
The meadow and trees of Andalucia

It is the biggest city in Andalucia region.
One of the tower of Plaza de Espana
A horse carriage outside the bank of Spain
Iglesia Colegial del Divino Salvador, the church of El Salvador, built in the 17th century
The Sevilla Cathedral, largest Gothic cathedral in the world


It is the birth place of Pablo Picasso and the gateway to Costa del Sol, Andalucia's sun drenched region.
Playa de la Malagueta
The morning of Malaga city seen from Alcazaba Fort
The Alcazaba Fort, built in 11th century, and the Roman theatre from 4th century
The Malaga cathedral and the moon next to it

It is the site of the last Islamic Kingdom in Spain.
A scenery in Albaicin
The Alhambra, the palace
A man walking in Albaicin
at Alhambra
A cathedral
outside a hotel
the Alhambra