Monday, July 25, 2016

Retrieve Data From MySQL Database in Android

<?php

if($_SERVER['REQUEST_METHOD']=='GET'){

$id  = $_GET['id'];

require_once('dbConnect.php');

$sql = "SELECT * FROM colleges WHERE id='".$id."'";

$r = mysqli_query($con,$sql);

$res = mysqli_fetch_array($r);

$result = array();

array_push($result,array(
"name"=>$res['name'],
"address"=>$res['address'],
"vc"=>$res['vicechancellor']
)
);

echo json_encode(array("result"=>$result));

mysqli_close($con);

}

dbConnect.php page code

<?php
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','androiddb');

$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');



    Creating a new Android Project

     Add  app 
    1
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    • Now create a new Java class in your package. I created Config.java. Here we will declare some important constants.
    package net.simplifiedcoding.gettingspecificdata;

    public class Config {
        public static final String DATA_URL = "http://192.168.94.1/Android/College/getData.php?id=";
        public static final String KEY_NAME = "name";
        public static final String KEY_ADDRESS = "address";
        public static final String KEY_VC = "vc";
        public static final String JSON_ARRAY = "result";
    }


    • For creating the above layout you can use the following xml 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editTextId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>
            <Button
                android:id="@+id/buttonGet"
                android:text="Get"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>
        <TextView
            android:id="@+id/textViewResult"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>
    MAINACtivite.java
    package net.simplifiedcoding.gettingspecificdata;

    import android.app.ProgressDialog;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.android.volley.RequestQueue;
    import com.android.volley.Response;
    import com.android.volley.VolleyError;
    import com.android.volley.toolbox.StringRequest;
    import com.android.volley.toolbox.Volley;

    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;

    public class MainActivity extends AppCompatActivity implements View.OnClickListener {

        private EditText editTextId;
        private Button buttonGet;
        private TextView textViewResult;

        private ProgressDialog loading;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            editTextId = (EditText) findViewById(R.id.editTextId);
            buttonGet = (Button) findViewById(R.id.buttonGet);
            textViewResult = (TextView) findViewById(R.id.textViewResult);

            buttonGet.setOnClickListener(this);
        }

        private void getData() {
            String id = editTextId.getText().toString().trim();
            if (id.equals("")) {
                Toast.makeText(this, "Please enter an id", Toast.LENGTH_LONG).show();
                return;
            }
            loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);

            String url = Config.DATA_URL+editTextId.getText().toString().trim();

            StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    loading.dismiss();
                    showJSON(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
                }
            });

            RequestQueue requestQueue = Volley.newRequestQueue(this);
            requestQueue.add(stringRequest);
        }

        private void showJSON(String response){
            String name="";
            String address="";
            String vc = "";
            try {
                JSONObject jsonObject = new JSONObject(response);
                JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
                JSONObject collegeData = result.getJSONObject(0);
                name = collegeData.getString(Config.KEY_NAME);
                address = collegeData.getString(Config.KEY_ADDRESS);
                vc = collegeData.getString(Config.KEY_VC);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            textViewResult.setText("Name:\t"+name+"\nAddress:\t" +address+ "\nVice Chancellor:\t"+ vc);
        }

        @Override
        public void onClick(View v) {
            getData();
        }
    }


    CREATE OR REPLACE FUNCTION

    CREATE OR REPLACE FUNCTION get_dname( p_deptno IN NUMBER )
      RETURN VARCHAR2
    IS
      l_dname VARCHAR2(30);
    BEGIN
      SELECT dname
        INTO l_dname
        FROM dept
       WHERE deptno = p_deptno;
      RETURN l_dname;
    END;

    PACKAGE BOdy

    CREATE OR REPLACE PACKAGE BODY cv_types AS
      PROCEDURE get_employees(deptid in number,
                              employees in out empinfotyp)
      IS
      BEGIN
        OPEN employees FOR
          SELECT employee_id,
            substr(first_name,1,1) || '. '|| last_name as employee_name,
            hire_date,
            to_char(salary, '999G999D99') as salary,
            NVL(commission_pct,0) as commission_pct,
            to_char(calc_remuneration(salary, commission_pct),
                    '9999G999D99') as remuneration
          FROM employees
          WHERE department_id = deptid
          ORDER BY employee_id ASC;
      END get_employees;
    END cv_types;

    How To Execute a Stored Procedure?

    How To Execute a Stored Procedure?
    If you want to execute a stored procedure, you can use the EXECUTE statement. The example script below shows how to executes a stored procedure:
    SQL> set serveroutput on;
    
    SQL> CREATE PROCEDURE Greeting AS
      2  BEGIN
      3    DBMS_OUTPUT.PUT_LINE('Welcome to FYICenter!');
      4  END;
      5  /
    Procedure created.
    
    SQL> EXECUTE Greeting;
    Welcome to FYICenter!

    Thursday, July 21, 2016

    Key Features of the Android Platform

    Key Features of the Android Platform
    Mobile app developers, mobile device manufacturers, and cell operators consider the Android platform as the most promising platform due to the cost efficiency in its production values. The popularity of the Android platform is mainly due to its numerous intriguing features. Some key features of the Android platform are:
    Integrated browser: Android provides an integrated Web browser, which is based on the open-source WebKit engine. SQLite: Android provides a powerful, fast, and lightweight relational database engine called SQLite. Android apps can store application data in a SQLite database. Media support: Android provides support for common audio, video, and still image formats such as MPEG4 SP, MP3, JPEG, PNG, and GIF. Wireless services: Android provides various options to connect to other devices. These

    connectivity options include:
    Bluetooth: An open wireless technology standard for exchanging data over short distances using short wavelength radio transmissions. Wireless Fidelity (Wi-Fi): A networking technology that does not require wires for devices to communicate with each other provided the devices are in the vicinity of an access point called a hotspot. Hotspots are commonly provided in public places, such as hotels, airports, coffee shops, and train stations to enable people to connect to the Internet through their devices. Dalvik Virtual Machine (DVM): Android apps are mostly written in Java programming language and are compiled into byte codes. Android byte codes are interpreted at runtime by DVM. Application framework: Android’s application framework allows app developers to build rich and innovative apps. These apps can access the same APIs that are used by the core apps provided by the Android platform. In addition, the application framework allows developers to reuse components published by other apps. Rich development environment: The Android ADT bundle provides a rich development environment, which includes: x x x x x The Eclipse + ADT plugin The Android SDK tools The Android platform tools The Android platform The Android system image for the emulator
    Android Versions
    Android has undergone a number of updates since its original release. The updates to the base operating system fix the bugs in the previous versions and also add new features. Each new version of the Android operating system is developed under a code name, which is the name of a dessert. The various versions of Android launched in an order are shown in the following animation:
    The following list describes the various Android versions: q

    Android 1.5 (Cupcake): This version was released in April 2009. This was a significant version that showcased the power of the Android platform. It has been said that this version was supposed to be version 1.2 but Google decided to make it a major revision and made it 1.5 instead and gave it the dessert name, Cupcake. Android 1.6 (Donut): This version was released in September 2009. It provides some advanced features such as: x
    x x x
    Integrated camera, camcorder, and gallery interface Google turn-by-turn navigation feature Updated voice search Updated search experience Android 2.0/2.1 (Eclair): Android 2.0 was released in October 2009. In December 2009, it was released with a bug fix version 2.0.1. Android 2.1 was released in January 2010. Most people consider these versions as a single release. It has features such as Bluetooth 2.1 support, flash and digital zoom for the camera, multitouch support, and live wallpapers. Android 2.2 (Froyo): This version was released in May 2010. This version mainly improved speed by adopting the JavaScript just-in-time compiler engine from the Google browser, Chrome. It improved browser support by adding features such as Flash 10.1 plug-in support and animated GIF support. Android 2.3 (Gingerbread): This version was released in March 2011. The new features in Android 2.3 are: x x x x New UI theme with simpler color scheme Redesigned on-screen keyboard New copy and paste functionality Better power management

    Better app management New downloads manager New camera app for accessing multiple cameras Support for extra large screens Android 3.0 (Honeycomb): This version was released as a beta version. It is specifically designed for mobile tablet devices, such as the new generation of Samsung Galaxy tabs and Motorola XOOM. Android 3.1 (Honeycomb): It is an updated version of Android 3.0. It includes new developer features, such as API for USB accessories and new input events ranging from mice, trackballs, and joysticks. Android 3.2 (Honeycomb): It is an updated version of Honeycomb. It includes features, such as media sync from SD card, compatibility zoom for fixed-sized apps, and extended API for managing screen support. Android 4.0 (Ice Cream Sandwich): It is a new version of Android, which provides a brand new look; however, it has some resemblance to Android Honeycomb. It provides various features, such as refined evolved UI, multitasking, resizable widgets, and lock screen actions. Android 4.0.3 (Ice Cream Sandwich): It is an updated version of Android 4.0. It includes enhancement in features, such as social stream API in contacts provider, calendar provider, home screen widgets, and spell checking. Android 4.1 (Jelly Bean): It is another newer version of Android, which provides several features, such as speedier interface, a new Camera app, offline voice typing, and significantly improved notifications. Android 4.2 (Jelly Bean): It is an updated version of Android 4.1, which provides an improved speed and simplicity of Android 4.1. It includes various new features, such as photo sphere, redesigned camera app, and new gesture typing keyboard.

    Key Features of the Android Platform

    Key Features of the Android Platform
    Mobile app developers, mobile device manufacturers, and cell operators consider the Android platform as the most promising platform due to the cost efficiency in its production values. The popularity of the Android platform is mainly due to its numerous intriguing features. Some key features of the Android platform are:
    Integrated browser: Android provides an integrated Web browser, which is based on the open-source WebKit engine. SQLite: Android provides a powerful, fast, and lightweight relational database engine called SQLite. Android apps can store application data in a SQLite database. Media support: Android provides support for common audio, video, and still image formats such as MPEG4 SP, MP3, JPEG, PNG, and GIF. Wireless services: Android provides various options to connect to other devices. These

    connectivity options include:
    Bluetooth: An open wireless technology standard for exchanging data over short distances using short wavelength radio transmissions. Wireless Fidelity (Wi-Fi): A networking technology that does not require wires for devices to communicate with each other provided the devices are in the vicinity of an access point called a hotspot. Hotspots are commonly provided in public places, such as hotels, airports, coffee shops, and train stations to enable people to connect to the Internet through their devices. Dalvik Virtual Machine (DVM): Android apps are mostly written in Java programming language and are compiled into byte codes. Android byte codes are interpreted at runtime by DVM. Application framework: Android’s application framework allows app developers to build rich and innovative apps. These apps can access the same APIs that are used by the core apps provided by the Android platform. In addition, the application framework allows developers to reuse components published by other apps. Rich development environment: The Android ADT bundle provides a rich development environment, which includes: x x x x x The Eclipse + ADT plugin The Android SDK tools The Android platform tools The Android platform The Android system image for the emulator
    Android Versions
    Android has undergone a number of updates since its original release. The updates to the base operating system fix the bugs in the previous versions and also add new features. Each new version of the Android operating system is developed under a code name, which is the name of a dessert. The various versions of Android launched in an order are shown in the following animation:
    The following list describes the various Android versions: q

    Android 1.5 (Cupcake): This version was released in April 2009. This was a significant version that showcased the power of the Android platform. It has been said that this version was supposed to be version 1.2 but Google decided to make it a major revision and made it 1.5 instead and gave it the dessert name, Cupcake. Android 1.6 (Donut): This version was released in September 2009. It provides some advanced features such as: x
    x x x
    Integrated camera, camcorder, and gallery interface Google turn-by-turn navigation feature Updated voice search Updated search experience Android 2.0/2.1 (Eclair): Android 2.0 was released in October 2009. In December 2009, it was released with a bug fix version 2.0.1. Android 2.1 was released in January 2010. Most people consider these versions as a single release. It has features such as Bluetooth 2.1 support, flash and digital zoom for the camera, multitouch support, and live wallpapers. Android 2.2 (Froyo): This version was released in May 2010. This version mainly improved speed by adopting the JavaScript just-in-time compiler engine from the Google browser, Chrome. It improved browser support by adding features such as Flash 10.1 plug-in support and animated GIF support. Android 2.3 (Gingerbread): This version was released in March 2011. The new features in Android 2.3 are: x x x x New UI theme with simpler color scheme Redesigned on-screen keyboard New copy and paste functionality Better power management

    Better app management New downloads manager New camera app for accessing multiple cameras Support for extra large screens Android 3.0 (Honeycomb): This version was released as a beta version. It is specifically designed for mobile tablet devices, such as the new generation of Samsung Galaxy tabs and Motorola XOOM. Android 3.1 (Honeycomb): It is an updated version of Android 3.0. It includes new developer features, such as API for USB accessories and new input events ranging from mice, trackballs, and joysticks. Android 3.2 (Honeycomb): It is an updated version of Honeycomb. It includes features, such as media sync from SD card, compatibility zoom for fixed-sized apps, and extended API for managing screen support. Android 4.0 (Ice Cream Sandwich): It is a new version of Android, which provides a brand new look; however, it has some resemblance to Android Honeycomb. It provides various features, such as refined evolved UI, multitasking, resizable widgets, and lock screen actions. Android 4.0.3 (Ice Cream Sandwich): It is an updated version of Android 4.0. It includes enhancement in features, such as social stream API in contacts provider, calendar provider, home screen widgets, and spell checking. Android 4.1 (Jelly Bean): It is another newer version of Android, which provides several features, such as speedier interface, a new Camera app, offline voice typing, and significantly improved notifications. Android 4.2 (Jelly Bean): It is an updated version of Android 4.1, which provides an improved speed and simplicity of Android 4.1. It includes various new features, such as photo sphere, redesigned camera app, and new gesture typing keyboard.

    MOBILE APP

    Fundamentals of Mobile App Development
    Since the beginning of this information age (21st Century), our society has witnessed remarkable growth in technology, which has affected our lifestyle in various ways. For example, technology has remarkably transformed our education system. Computers are being widely used for education delivery. Online education is also gaining rapid popularity. Technology has been growing at a rapid pace to accommodate the needs and desires of people for obtaining a simpler and an immaculate lifestyle. Mobile devices are one of the greatest technological advancements that have hit the 21st Century. Today, there is a tremendous usage of gadgets ranging from Personal Computers (PCs) to Personal Digital Assistants (PDAs) to featured cellular phones in our
    everyday life. As per the demand for usability and needs of a consumer, all device manufacturers are continuously innovating and rolling out new and innovative products. Mobile devices, such as PDAs, Tabs, and smartphones, allow people to access the Internet for different purposes, such as sending e-mails, instant messaging, text messaging, and Web browsing. In addition, these mobile devices allow users to even perform professional tasks, such as managing documents and presentations. To perform each of these tasks through a mobile device, you need to install an appropriate mobile app on your mobile device. A mobile app is software that runs on a mobile device. Mobile apps can entertain, educate, and assist users on a daily basis. These mobile apps provide the user with several services, such as communication and messaging, contact management, audio/video, gaming, and network connectivity.

    Types of Mobile Apps
    Mobile apps can be divided into various categories according to their usage. Some key categories of mobile apps are: 

    Multimedia apps: These include video players, audio players, live TV players, and graphics/ image viewers. Travel apps: These include currency convertors, language translators, and weather forecasters. Utilities: These include contact manager, task manager, and call manager. Web-based apps: These include search tools, instant messaging tools, and Web browsers. Communication apps: These include e-mail (Gmail/corporate/others), WhatsApp, Viber, and Skype, and so on for voice-to-voice/video calling and instant messaging. Enterprise apps: These include office productivity tools, such as Microsoft Office Mobile and ThinkFree. Productivity apps: These include calendars, calculators, and memo pad. Social networking apps: These include social networking sites, such as Facebook and Twitter. Location-based apps: These include map-based apps, such as Google maps and Bing maps. Gaming apps: These include various types of games, such as puzzles, cards, and sports






    tree in c

    #include<stdlib.h>
    #include<stdio.h>

    struct bin_tree {
    int data;
    struct bin_tree * right, * left;
    };
    typedef struct bin_tree node;

    void insert(node ** tree, int val)
    {
        node *temp = NULL;
        if(!(*tree))
        {
            temp = (node *)malloc(sizeof(node));
            temp->left = temp->right = NULL;
            temp->data = val;
            *tree = temp;
            return;
        }

        if(val < (*tree)->data)
        {
            insert(&(*tree)->left, val);
        }
        else if(val > (*tree)->data)
        {
            insert(&(*tree)->right, val);
        }

    }

    void print_preorder(node * tree)
    {
        if (tree)
        {
            printf("%d\n",tree->data);
            print_preorder(tree->left);
            print_preorder(tree->right);
        }

    }

    void print_inorder(node * tree)
    {
        if (tree)
        {
            print_inorder(tree->left);
            printf("%d\n",tree->data);
            print_inorder(tree->right);
        }
    }

    void print_postorder(node * tree)
    {
        if (tree)
        {
            print_postorder(tree->left);
            print_postorder(tree->right);
            printf("%d\n",tree->data);
        }
    }

    void deltree(node * tree)
    {
        if (tree)
        {
            deltree(tree->left);
            deltree(tree->right);
            free(tree);
        }
    }

    node* search(node ** tree, int val)
    {
        if(!(*tree))
        {
            return NULL;
        }

        if(val < (*tree)->data)
        {
            search(&((*tree)->left), val);
        }
        else if(val > (*tree)->data)
        {
            search(&((*tree)->right), val);
        }
        else if(val == (*tree)->data)
        {
            return *tree;
        }
    }

    void main()
    {
        node *root;
        node *tmp;
        //int i;

        root = NULL;
        /* Inserting nodes into tree */
        insert(&root, 9);
        insert(&root, 4);
        insert(&root, 15);
        insert(&root, 6);
        insert(&root, 12);
        insert(&root, 17);
        insert(&root, 2);

        /* Printing nodes of tree */
        printf("Pre Order Display\n");
        print_preorder(root);

        printf("In Order Display\n");
        print_inorder(root);

        printf("Post Order Display\n");
        print_postorder(root);

        /* Search node into tree */
        tmp = search(&root, 4);
        if (tmp)
        {
            printf("Searched node=%d\n", tmp->data);
        }
        else
        {
            printf("Data Not found in tree.\n");
        }

        /* Deleting all nodes of tree */
        deltree(root);
    }