Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Saturday, 12 November 2016

LRC (longitudinal redundancy check)

LRC stands for longitudinal redundancy check In telecommunication, a longitudinal redundancy check (LRC) or horizontal redundancy check is a form of redundancy check that is applied independently to each of a parallel group of bit streams. The data must be divided into transmission blocks, to which the additional check data is added.



[ SENDER SIDE ]

#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getBinary(int num,int pos)
{
 int code=1;
 code=code<<(pos-1);
 if(num & code)
  return 1;
 else
  return 0;
}
findLRC(char str[][50],int no_of_str,char parity[50])
{
int count = 0 , j = 0 , i = 0 ;
int k = 0 ;
printf("\n\n");
for(i = 0 ; i < 8 ; i++)
{
for(j = 0 ; j < no_of_str ; j++)
{
//printf("%c",str[j][i]);
if(str[j][i]=='1')
{
count++ ;
}
}
if(count % 2 == 0)
{
parity[k] = '0' ;
}
else
{
parity[k] = '1' ;
}
k++ ;
count = 0 ;
}
parity[k] = '\0';
}
void generateError(char ans[])
{
 int exitflag=1,pos;
 do
 {
  printf("Enter Position : ");
  scanf("%d",&pos);
  if(pos>=0 && pos<strlen(ans))
  {
   if(ans[pos]=='1')
    ans[pos]='0';
   else
    ans[pos]='1';
  }
  else
  {
   printf(" \t>>>Position is out of range<<<\n");
  }
  printf("Want to Generate More Error (1 / 0) : ");
  scanf("%d",&exitflag);
 }while(exitflag==1);
}

int main()
{
int no_of_data ;
int i = 0 ;
int arr[10];

char str[10][50];
char parity[50];
char data[80];

printf("\n How many data : ");
scanf("%d",&no_of_data);
for(i=0;i<no_of_data;i++)
{
printf("\n Enter number : ");
scanf("%d",&arr[i]);
printf("\n No is %d " , arr[i]);
}
int j ;int k = 0 ;
for(i=0;i<no_of_data;i++)
{
for(j=8;j>0;j--)
{
  str[i][k++]=getBinary(arr[i],j)+48;
}
str[i][k]='\0';
k = 0 ;
}
for(i=0;i<no_of_data;i++)
{
printf("\n Binary is %s",str[i]);
}
findLRC(str,no_of_data,parity);
printf("\n Parity is %s ", parity);
for(i=0;i<no_of_data;i++)
{
strcat(data,str[i]);
}
int flag = 0 ;
printf("\n Want to Generate Error (1 / 0) : ");
  scanf("%d",&flag);
  if(flag==1)
  {
  generateError(data);
  printf("\n======================================================");
  printf("\nData to Be Send With Parity and with Error : %s",data);
  printf("\n======================================================\n");
  }

strcat(data,parity);

int pid ;
system(">pipe");
pid = open("pipe",O_WRONLY);
printf("\n Final data is %s " , data);
write(pid,&no_of_data,sizeof(no_of_data));
write(pid,&data,sizeof(data));
return 0 ;
}



[ RECEIVER SIDE ]


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getBinary(int num,int pos)
{
 int code=1;
 code=code<<(pos-1);
 if(num & code)
  return 1;
 else
  return 0;
}
findLRC(char str[][50],int no_of_str,char parity[50])
{
int count = 0 , j = 0 , i = 0 ;
int k = 0 ;
printf("\n\n");
for(i = 0 ; i < 8 ; i++)
{
for(j = 0 ; j < no_of_str ; j++)
{
//printf("%c",str[j][i]);
if(str[j][i]=='1')
{
count++ ;
}
}
if(count % 2 == 0)
{
parity[k] = '0' ;
}
else
{
parity[k] = '1' ;
}
k++ ;
count = 0 ;
}
parity[k] = '\0';
}
void main()
{
int no,j=0,len,i=0,k,pid;
char data[80];//={"000000010000001011"}//1 = 00000001, 2 = 00000010, parity = 11
int no_of_data=2;
char totalData;
char parity[50];
pid=open("pipe",O_RDONLY);

//Commenting this as it is not working in windows
read(pid,&no_of_data,sizeof(no_of_data));
read(pid,&data,sizeof(data));


printf("\nno of data : %d",no_of_data);
printf("\ndata : %s",data);
k = 0 ;
char str[15][50];
k=0;
for(i=0;i<no_of_data;i++)
{
for(j=0;j<8;j++)
{
str[i][j] = data[k++];
str[i][j+1] = '\0';
}
}
for(i=0;i<no_of_data;i++)
{
printf("\n Str is %s",str[i]);
}

findLRC(str,no_of_data,parity);
char redaparity[50];
j=0;
for(i=no_of_data*8;i<strlen(data);i++){
redaparity[j++]=data[i];
}
redaparity[j]='\0';

printf("\nReceived parity %s", redaparity);
printf("\nCalculated parity %s", parity);
int isSame=strcmp(redaparity, parity);
if(isSame==0){
printf("\nDATA IS CORRECT");
}
else{
printf("\nDATA IS INCORRECT");
}

}



Monday, 31 October 2016

Now Great News For Students / Job Seekers !!!


We are providing Software Training in following Subjects



Basic Level:
1. C
2. C++

Programming Level
1. JAVA
2. PHP

Database:

1. SQL, MYSQL, PLSQL
2. ORACLE

Web:

1. CSS, CSS-3,
2. Bootstrap, 

3. HTML, HTML-5

Mobile Computing:

1. Android

Extras:
1. FON (Fundamental Of Networking) Practicals for MCA Students

For more detail please Contact Us on below numbers


Ahmedabad-Gujarat Region

Ami Sharma (M-9712630253, 7990318870)
Pankaj Sharma(M-8460479175)

Thursday, 27 June 2013

How to use Command line argument in GCC compiler

[Sender.c]
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main(int argc, char *args[])
{
int i,count=0,len,j=0,pid;
char frame[50],data[50];
        len=strlen(args[1])-8;

system("clear");
system(">pipe");
pid=open("pipe",O_WRONLY);

printf("len : %d",len);
printf("%s",data);

for(i=0; i<len; i++)
{
data[i]=args[1][8+i];
}
data[i]='\0';
printf("data %s",data);

frame[j]=len+48;
for(i=0; i<len; i++)
{
j++;
frame[j]=data[i];
}
j++;
frame[j]='\0';
printf(" Sent to frame :%s",frame);
write(pid,&frame,sizeof(frame));
}

[Receiver.c]

#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int i,count=0,len,j=0,pid;
char frame[50],data[50];
        system("clear");
pid=open("pipe",O_RDONLY);
read(pid,&frame,sizeof(frame));
printf("%s",frame);
len=strlen(frame);
for(i=0; i<len; i++)
{
data[i]=frame[i+1];
}
data[i]='\0';
printf("data %s",data);
printf("\n receive to frame :%s",data);
}




Tuesday, 22 January 2013

Mysql java connectivity

hi Friends here are the steps to connect java with mysql database
step 2: on your c: drive find "mysql" directory and copy above connector file in "mysql/lib" dirctory.
step 3: right click on mycomputer->properties->advance-system-setting->Environment_variable
step 4: add new variable and set 
VARIABLE NAME=CLASSPATH
VARIABLE VALUE=;C:/<YOUR DIRECTORYs>/mysql/lib/mysql-connector-java-5.1.2.jar;
step 5: click on ok->ok->ok
step 6: write following code
import java.sql.*;
import java.io.*;
public class connect
{
 /*
 * master-gtu.blogspot.com
 * Pankaj Sharma(8460479175)
 */
 public static void main(String args[])
 {
  try
  {
  Class.forName("com.mysql.jdbc.Driver");
  Connection con=DriverManager.getConnection("jdbc:mysql://localhost/neelkanth","root","");
// here neelkanth is database name and root is username and password is blank
  //System.out.println("Connected to DATABASE");
  Statement stmt = con.createStatement();
  ResultSet rs=stmt.executeQuery("select * from notice");
  while(rs.next())
  {
   System.out.println(rs.getString(3));
  }
  con.close();
  }
  catch(Exception e)
  {
   System.out.println(e.toString());
  }
 }
}
step 7: Wao connectivity success... """""""""Happy Coding"""""""""""

Monday, 26 November 2012

Create user friendly application that show different shapes like circle, square, rectangle, round rectangle, arc, oval in listview and on selecting draw that shape using ShapeDrawable class

Set7Activity.java
package ps.set7;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Set7Activity extends Activity implements OnItemClickListener 
{
 /**
     * www.master-gtu.blogspot.com
     * pankaj sharma (8460479175)
     * vijay chavda  (8460420769) 
     */
 String flags[]={"circle","square","rectangle","round rect","arc","oval"};
 ListView lv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        lv=(ListView) findViewById(R.id.listView1);
        
        ArrayAdapter<String>aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,flags);
        lv.setAdapter(aa);
        lv.setOnItemClickListener(this);
    }
 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
 {
  Intent i=new Intent(this, screen.class);
  i.putExtra("id", arg2);
  startActivity(i);
 }
}
screen.java
package ps.set7;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.os.Bundle;
import android.view.View;

public class screen extends Activity 
{
 /**
     * www.master-gtu.blogspot.com
     * pankaj sharma (8460479175)
     * vijay chavda  (8460420769) 
     */
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(new screen1(this,getIntent().getIntExtra("id", 0)));
 }
 private class screen1 extends View
 {
  int shape=0;
  public screen1(Context context, int id) {
   super(context);
   shape=id;
  }
  @Override
  protected void onDraw(Canvas canvas) {
   // TODO Auto-generated method stub
   super.onDraw(canvas);
   Shape s=new Shape() {
    
    @Override
    public void draw(Canvas c, Paint paint) 
    {
     paint.setColor(Color.RED);
     if(shape==0)
     {
      c.drawCircle(100, 100, 50, paint);
     }
     else if(shape==1)
     {
      c.drawRect(100, 100, 200, 200,paint);
     }
     else if(shape==2)
     {
      c.drawRect(100, 100, 150, 200, paint);
     }
     else if(shape==3)
     {
      RectF rect=new RectF(100, 100, 150, 200);
      c.drawRoundRect(rect, 5, 5, paint);
     }
     else if(shape==4)
     {
      RectF rect=new RectF(100, 100, 150, 200);
      c.drawArc(rect, 0, 150, true, paint);
     }
     else if(shape==5)
     {
      RectF rect=new RectF(100, 100, 150, 200);
      c.drawOval(rect,paint);
     }
    }
   };
   
   ShapeDrawable obj=new ShapeDrawable();
   obj.setShape(s);
   obj.draw(canvas);
  }
 }
}

Create android application that shows different country flags on listview and on selecting it will show flag of that country

Set6Activity.java
package ps.set6;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;

public class Set6Activity extends Activity implements OnItemClickListener {
    /**
     * www.master-gtu.blogspot.com
     * pankaj sharma (8460479175)
     * vijay chavda  (8460420769) 
     */
 String flags[]={"india","bhutan","nepal","japan"};
 int id[]={R.drawable.india,R.drawable.bhutan,R.drawable.nepal,R.drawable.japan};
 ListView lv;
 ImageView img;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        lv=(ListView) findViewById(R.id.listView1);
        img=(ImageView) findViewById(R.id.imageView1);
        
        ArrayAdapter<String>aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,flags);
        lv.setAdapter(aa);
        lv.setOnItemClickListener(this);
    }
 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
 {
  img.setImageResource(id[arg2]);
 }
}

Sunday, 18 November 2012

Write a Script for Simple Database Management System Operation


clear
echo "\nDATABASE MANAGEMENT SYSTEM OPERATION\n"
echo "-----------------------------------------"
echo "1. VIEW RECORD BASES ON QUERY"
echo "2. ADD RECORD"
echo "3. DELETE RECORD"
echo "4. COUNT TOTAL NUMBER OF RECORD"
echo "5. EXIT"
echo "Enter your choice"
read ch
case $ch in
1)
echo " * Serching Record * "
echo "1. EMP_NO"
echo "2. EMP_NAME"
echo "3. EMP_ADDRESS"
echo "4. EMP_AGE"
echo "5. EMP_GENDER"
echo "6. EMP_DESIGNATION"
echo "7. EMP_BASIC_SALARY"
read serch_choice
case $serch_choice in
1)
echo "Enter Employee NO "
read empno
empno=`expr $empno + 1`

head -$empno emp.txt > temp1

tail -1 temp1 > temp2
no= `awk '{print $1}' temp2`
echo $no
;;
2)
echo "Enter Employee's Name"
read empname
grep "$empname" emp.txt
;;
3)
echo "Enter Address"
read empadd
grep "$empadd" emp.txt
;;
4)
echo "Enter Age"
read age
grep "$age" emp.txt
;;
5)
echo "Enter Gender"
read gender
grep "$gender" emp.txt
;;
6)
echo "Enter Designation"
read empdesig
grep "$empdesig" emp.txt
;;

7)
echo "Enter Basic Salary"
read bs
grep "$bs" emp.txt
;;
8)
echo "wrong choice"
;;
esac
;;
2)
echo "Enter emp_no : "
read empno
echo "Enter emp_name : "
read empname
echo "Enter address : "
read empadd
echo "Enter age : "
read age
echo "Enter Gender : "
read gender
echo "Enter designation : "
read empdesig
echo "Enter basic salary : "
read bs
record="$empno|$empname|$empaddr|$age|$gender|$empdesig|$bs"
`echo $record>>emp.txt`
echo " \t Record insert successfully..."
;;
3)
echo "Enter name"
read name
#`sed "/$name/d" emp.txt>tempfile1`
`grep -w "/$name/d" emp.txt>tempfile1`
`cat tempfile1>emp.txt`
rm tempfile1
  echo "\t Record delete successfully..."
;;
4) echo "Enter name"
read name
`sed "/$name/d" emp.txt>tempfile1`
`cat tempfile1>emp.txt`
rm tempfile1
echo "Enter emp_no : "
read empno
echo "Enter emp_name : "
read empname
echo "Enter address : "
read empadd
echo "Enter age : "
read age
echo "Enter Gender : "
read gender
echo "Enter designation : "
read empdesig
echo "Enter basic salary : "
read bs
record="$empno|$empname|$empaddr|$age|$gender|$empdesig|$bs"
`echo $record>>emp.txt`
echo " \t Record modify successfully..."
;;
Esac

Wednesday, 14 November 2012

Simple Gallery View Example in android

Demo18Activity.java
package ps.demo18;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;

public class Demo18Activity extends Activity implements OnItemClickListener {
    /** 
     * www.master-gtu.blogspot.com
     * pankaj sharma(8460479175), 
     * chavda vijay(8460420769) 
     */
 Gallery gv;
 int images[]={R.drawable.photo1,R.drawable.photo2,R.drawable.photo3,R.drawable.photo4};
 ImageView img;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        gv=(Gallery) findViewById(R.id.gallery1);
        
        img=(ImageView) findViewById(R.id.imageView1);
        
        gv.setAdapter(new arrayAdapter(this));
        
        gv.setOnItemClickListener(this);
    }
    private class arrayAdapter extends BaseAdapter
    {
     int images[]={R.drawable.photo1,R.drawable.photo2,R.drawable.photo3,R.drawable.photo4};
     Context c;
     public arrayAdapter(Context context)
     {
      c=context;
     }
  @Override
  public int getCount() {
   // TODO Auto-generated method stub
   return images.length;
  }

  @Override
  public Object getItem(int arg0) {
   // TODO Auto-generated method stub
   return arg0;
  }

  @Override
  public long getItemId(int arg0) {
   // TODO Auto-generated method stub
   return arg0;
  }

  @Override
  public View getView(int arg0, View arg1, ViewGroup arg2) {
   // TODO Auto-generated method stub
   
   ImageView img = new ImageView(c);
   img.setImageResource(images[arg0]);
   img.setLayoutParams(new Gallery.LayoutParams(100, 200));
   
   return img;
  }
    }
 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  // TODO Auto-generated method stub

  img.setImageResource(images[arg2]);
  Toast.makeText(this, images[arg2]+" selected", 1).show();
 }
}

Wednesday, 7 November 2012

Literature Survey & Acknowledgement


Acknowledgement

There are a number of people whom I would like to thank for their help and support in the creation of this dissertation!

I would like to thank the lecturers and staff of JVIMS for their support, guidance and patience but especially Prof. Apexa Joshi for her support as thesis advisor. Her encouragement at all stages of this project work has been contributed greatly to present the contents of the project.

We are grateful to Prof. Apexa Joshi, Seema Makhecha(H.O.D), Dr. K.J.Thankanchand Director of JVIMS M.C.A. College, for allowing us to carry out our dissertation work.

We would also like to thank all the staff members of the computer department, college library which provided us lot of valuable information regarding our project and for their understanding
whenever I required time to study or research. Last but not the least; we are obliged to our parents & all those who have directly or indirectly helped us to make this dissertation happen.


Literature survey


  1. How does a webmaster ensure that they appear high on search results? The answer is SEO(search engine optimization). Jerri Ledford (2008) defines the term SEO as “Improving a web site in an attempt to attract search engine crawlers”. A crawler is a piece of software that selects websites and indexes their contents for the purposes of building a search database.
  2. SEO is not a new idea; it has been around nearly as long as the search engines. However with the massive increase in traffic and usage on the internet, it has become a hugely important part of the design process. We use various techniques like keyword research, link building etc.
  3. This dissertation sets out to determine and document the main search engine optimization techniques used today i.e. Keyword research which is most important. The final part of the dissertation will apply all this to techniques to website for optimizing our site in search engine ranking.


Friday, 26 October 2012

Create an application to open any URL inside the application and clicking on any link from that URl should not open Native browser but that URL should open the same screen.

Note:Give "INTERNET" permission in android Manifest file.
WebViewActivity.java
package ps.webview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class WebviewActivity extends Activity implements OnClickListener 
{
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */

//CREATE WEBVIEW OBJECT
 WebView web;
 TextView edurl;
 Button btgo;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // INTIALIZE WEBVIEW OBJECT
        // GIVE PERMISSION INTERNET IN ANDROIDMAINFEST FILE
        
        web=(WebView) findViewById(R.id.webView1);
        edurl=(TextView) findViewById(R.id.editTexturl);
        btgo=(Button) findViewById(R.id.buttongo);
        
        btgo.setOnClickListener(this);
    }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  if(edurl.getText().toString().equals(""))
  {
   Toast.makeText(this, "Pls Enter URL...", 1).show();
  }
  else 
  {
   String stringurl=edurl.getText().toString();
   
   if(!stringurl.startsWith("http://") &amp;&amp;  !stringurl.startsWith("https://") )
    stringurl="http://"+stringurl;
   
   //ENABELING JAVA SCRIPT ON WEBVIEW
   web.getSettings().setJavaScriptEnabled(true);
   
   //LOAD URL ON WEBVIEW
   web.loadUrl(stringurl);

   //SETTING WEBVIEW CLIENT TO OPEN IN SAME SCREEN NOT ON NATIVE BROWSER
   web.setWebViewClient(new WebViewClient());
  }
 }
}

Friday, 19 October 2012

Simple Database Operation Example In Android

QUESTION
 Develop an android application for student marks sheet
   a. create student database on SDcard
   b. create table
    i.  student { sno, name, dob }
    ii. marks { sno, s1, s2, s3 }
   c. action to be performed
    i.   Add record
    check for duplication
    ii.  View record
    sno, name, total, per, grade
    iii. Search record
    search by no and name
    iv.  Delete record
 
   With Proper Validation

DatabaseActivity.java
package ps.database;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class DatabaseActivity extends Activity implements OnItemClickListener, TextWatcher {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView lv;
 SQLiteDatabase db;
 TextView edsearchbyno;
 
  String names[];
 TextView edsearchbyname;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        db=openOrCreateDatabase("/sdcard/database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
        db.execSQL("create table if not exists student(sno text, name text, dob text)");
        db.execSQL("create table if not exists marks(sno text, s1 text, s2 text, s3 text)");
        lv=(ListView) findViewById(R.id.listView1);
        
        Cursor cur=db.rawQuery("select * from student", null);
names=new String[cur.getCount()];
for(int i=0;i<cur.getCount();i++)
{
 cur.moveToNext();
 names[i]=cur.getstring(0)+". "+cur.getString(1);
}
ArrayAdapter<"String">arr=new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1,names);
lv.setAdapter(arr);
lv.setOnItemClickListener(this);
        
        //===============================
        
        edsearchbyname=(TextView) findViewById(R.id.editTextsearchname);
        
        edsearchbyname.addTextChangedListener(this);
        
        //===============================
    }
 @Override
 public void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) {
  // TODO Auto-generated method stub
  Intent myintent =new Intent(this,view.class);
  myintent.putExtra("pos", names[pos].substring(0, names[pos].indexOf('.'))+"");
  Toast.makeText(this,names[pos].substring(0, names[pos].indexOf('.'))+" ",1).show();
  startActivity(myintent);
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  super.onCreateOptionsMenu(menu);
  menu.add(0,0,0,"INSERT");
  menu.add(0,1,1,"REFERESH");
  return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  super.onOptionsItemSelected(item);
  if(item.getItemId()==0)
  {
   
   startActivity(new Intent(this,insert.class));
  }
  else if(item.getItemId()==1)
  {
   
   startActivity(new Intent(this,DatabaseActivity.class));
  }
  return true;
 }
 //======================searching===========================
 @Override
 public void afterTextChanged(Editable arg0) {
  // TODO Auto-generated method stub
  Cursor cur=db.rawQuery("select * from student where name like '%"+edsearchbyname.getText().toString()+"%'", null);
  if(cur.getCount()>0)
  {
   names=new String[cur.getCount()];
names=new String[cur.getCount()];
for(int i=0;i<cur.getCount();i++)
{
 cur.moveToNext();
 names[i]=cur.getstring(0)+". "+cur.getString(1);
}
ArrayAdapter<"String">arr=new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1,names);
lv.setAdapter(arr);
lv.setOnItemClickListener(this);
   lv.setAdapter(arr);
  }
 }
 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
  
 }
}

view.java
package ps.database;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class view extends Activity implements OnClickListener
{
 EditText edno,edname,edtotal,edper,edgrade;
 Button btdelete;
 SQLiteDatabase db;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.view);
  
  db=openOrCreateDatabase("/sdcard/database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
  edno=(EditText) findViewById(R.id.editTextviewnumber);
  edname=(EditText) findViewById(R.id.editTextviewname);
  edtotal=(EditText) findViewById(R.id.editTexttotal);
  edper=(EditText) findViewById(R.id.editTextper);
  edgrade=(EditText) findViewById(R.id.editTextgrade);
  
  btdelete=(Button) findViewById(R.id.buttondelete);
 
  String pos=getIntent().getStringExtra("pos");
  
  Cursor cur=db.rawQuery("select * from student where sno='"+pos+"'", null);
  
  cur.moveToNext();
  
  edno.setText(cur.getString(0));
  edname.setText(cur.getString(1));
  cur.close();
  
  cur=db.rawQuery("select * from marks where sno='"+edno.getText().toString()+"'", null);
  cur.moveToNext();
  int total=Integer.parseInt(cur.getString(1)+"") +Integer.parseInt(cur.getString(2)+"") +Integer.parseInt(cur.getString(3)+"");
  edtotal.setText(total+"");
  int per=total/3;
  edper.setText(total/3+"");
  if(per>65)
   edgrade.setText("A");
  else if(per<=65)
   edgrade.setText("B");

  edno.setEnabled(false);
  edname.setEnabled(false);
  edtotal.setEnabled(false);
  edper.setEnabled(false);
  edgrade.setEnabled(false);
  
  
  btdelete.setOnClickListener(this);
 }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(btdelete.getId()==v.getId())
  {
   try
   {
   db.execSQL("delete from student where sno='"+edno.getText().toString()+"'");
   db.execSQL("delete from marks where sno='"+edno.getText().toString()+"'");
   Toast.makeText(this, "Delete Success",1).show();
   }
   catch(Exception e)
   {
    Toast.makeText(this, e.toString(), 1).show();
   }
  }
 }
}
insert.java
package ps.database;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class insert extends Activity implements OnClickListener 
{
 EditText edsno,edname,eddob,eds1,eds2,eds3;
 Button btsave,btclear;
 SQLiteDatabase db;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.insert);
  
  db=openOrCreateDatabase("/sdcard/database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
  edsno=(EditText) findViewById(R.id.editTextinsertnumber);
  edname=(EditText) findViewById(R.id.editTextinsertname);
  eddob=(EditText) findViewById(R.id.editTextinsertdob);
  eds1=(EditText) findViewById(R.id.editTextinserts1);
  eds2=(EditText) findViewById(R.id.editTextinserts2);
  eds3=(EditText) findViewById(R.id.editTextinserts3);
  btsave=(Button) findViewById(R.id.buttoninsertsave);
  btclear=(Button) findViewById(R.id.buttoninsertclear);
  
  btsave.setOnClickListener(this);
  btclear.setOnClickListener(this);

 }

 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(btsave.getId()==v.getId())
  {
   Cursor cur=db.rawQuery("select * from student where sno='"+edsno.getText().toString()+"'", null);
   
   if(cur.getCount()>0)
   {
    Toast.makeText(this, "aleready exists..",1).show(); 
   }
   else 
   {
    if(edsno.getText().toString().equals("") || edname.getText().toString().equals("") || eddob.getText().toString().equals("") ||eds1.getText().toString().equals("")  || eds2.getText().toString().equals("") ||eds3.getText().toString().equals("") )
    {
     Toast.makeText(this, "Pls Enter All the fields", 1).show(); 
    }
    else 
    {
     db.execSQL("insert into student values('"+edsno.getText().toString()+"','"+edname.getText().toString()+"','"+eddob.getText().toString()+"')");
     db.execSQL("insert into marks values('"+edsno.getText().toString()+"','"+eds1.getText().toString()+"','"+eds2.getText().toString()+"','"+eds3.getText().toString()+"')");
    }

    Toast.makeText(this,"Insert success...", 1).show();
   }
  }
  else if(btclear.getId()==v.getId())
  {
   edsno.setText("");
   edname.setText("");
   eddob.setText("");
   eds1.setText("");
   eds2.setText("");
   eds3.setText("");
  }
 }
}

Thursday, 18 October 2012

Create an application to pick up any image from the native application gallery and display it on the screen.

Pro23Activity.java
Note :  Drop Images on Sdcard then go to menus open "Dev-Tools" -> "Media Scanner"
package ps.pro23;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class Pro23Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 
 ImageView img;
 Button btnext, btprevious;
 Cursor cur;
 int total,current;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        img=(ImageView) findViewById(R.id.imageView1);
        btnext=(Button) findViewById(R.id.buttonnext);
        btprevious=(Button) findViewById(R.id.buttonprevious);
        btprevious.setEnabled(false);
        
        btnext.setOnClickListener(this);
        btprevious.setOnClickListener(this);

//Note Media Class is inside MediaStore.Images for images [see 8th line]
        
        //Uri umedia=Uri.parse(Media.EXTERNAL_CONTENT_URI);
        Uri umedia=Uri.parse("content://media/external/images/media");
        
        cur=managedQuery(umedia, null, null,null,null);
        total=cur.getCount();
        
        current=1;
        cur.moveToNext();
        img.setImageBitmap(BitmapFactory.decodeFile(cur.getString(1)));       
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btnext.getId())
  {
   current++;
   cur.moveToNext();
   img.setImageBitmap(BitmapFactory.decodeFile(cur.getString(1)));
   if(current==total)
   {
    btnext.setEnabled(false);
   }
   btprevious.setEnabled(true);
  }
  else if(v.getId()==btprevious.getId())
  {
   current--;
   cur.moveToPrevious();
   img.setImageBitmap(BitmapFactory.decodeFile(cur.getString(1)));
   if(current==1)
   {
    btprevious.setEnabled(false);
   }
   btnext.setEnabled(true);
  }
 }
}

Create an application to take picture using native application.

Pro22Activity.java
Note: Give permission in manifest file as "android.permission.CAMERA"
package ps.pro22;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class Pro22Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 
 ImageView img;
 Button btcapture;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        img=(ImageView) findViewById(R.id.imageView1);
        btcapture=(Button) findViewById(R.id.buttoncapture);
        
        btcapture.setOnClickListener(this);
    }
    @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  Intent myintent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  startActivityForResult(myintent, 0);
 }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     // TODO Auto-generated method stub
     super.onActivityResult(requestCode, resultCode, data);
     Bitmap myimage=(Bitmap) data.getExtras().get("data");
     img.setImageBitmap(myimage);
    }
}

Create an application to send message between two emulators.

Pro21Activity.java
package ps.pro21;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Pro21Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText ednumber, edmsg;
 Button btsend;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ednumber=(EditText) findViewById(R.id.editTextnumber);
        edmsg=(EditText) findViewById(R.id.EditTextmsg);
        btsend=(Button) findViewById(R.id.buttonsend);
        
        btsend.setOnClickListener(this);
    }
    private void sendsms(String num,String msg)
    {
     SmsManager sms=SmsManager.getDefault();
     sms.sendTextMessage(num, null, msg, null, null);
    }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  sendsms(ednumber.getText().toString(),edmsg.getText().toString());;
 }
}

Create an application to draw line on the screen as user drag his finger.

Pro20Activity.java
package ps.pro20;

import android.app.Activity;
import android.os.Bundle;
public class Pro20Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new ScreenActivity(this));
    }
}
ScreenActivity.java
package ps.pro20;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;
public class ScreenActivity extends View 
{
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Paint paintBrush=new Paint(Paint.ANTI_ALIAS_FLAG);
 Path path=new Path();
 
 public ScreenActivity(Context context) {
  super(context);  
  paintBrush.setColor(Color.RED);
  paintBrush.setStrokeWidth(5);
  paintBrush.setStyle(Paint.Style.STROKE);
 }
 @Override
 protected void onDraw(Canvas canvas) {
  // TODO Auto-generated method stub
 super.onDraw(canvas);
  canvas.drawPath(path, paintBrush);
 }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
  // TODO Auto-generated method stub
  super.onTouchEvent(event);
  
  //------getting position-------
  
  float x=event.getX();
  float y=event.getY();
  
  switch(event.getAction())
  {
   case MotionEvent.ACTION_DOWN:
    path.moveTo(x, y);
    return true;
    
   case MotionEvent.ACTION_MOVE:
    path.lineTo(x, y);
    break;
  }
  invalidate();
  return true; 
 }
}

Create an application to read file from the sdcard and display that file content to the screen.

Pro19Activity.java
package ps.pro19;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Pro19Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView tvcontent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        tvcontent=(TextView) findViewById(R.id.textView2);
        
        try
        {
         File myFile=new File("/sdcard/hello.txt");
         InputStream in=null;
         in=new FileInputStream(myFile);
         
         String msg="";
         while(in.available()>0)
         {
          msg=msg+(char)in.read();
         }
         in.close();
         tvcontent.setText(msg);

        }
        catch(Exception e)
        {
         Toast.makeText(this, e.toString(),Toast.LENGTH_LONG).show();
        }
    }
}

Create an application to make Insert , update , Delete and retrieve operation on the database.

DataBaseActivity.java
package vc.dataBase;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class DataBaseActivity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       // db.openDatabase("Data1",SQLiteDatabase.CREATE_IF_NECESSARY,null);
        db=openOrCreateDatabase("Data1",SQLiteDatabase.CREATE_IF_NECESSARY,null);
        db.execSQL("create table if not exists student(id integer primary key, name text not null,age integer not null,phone text not null)");
    }
    public boolean onCreateOptionsMenu(Menu menu)
    {
     
     super.onCreateOptionsMenu(menu);
     //When You are put icon in Menu then create the Menu item object
     
     menu.add(0,0,0,"Insert");
     menu.add(0,1,0,"Update");
     menu.add(0,2,0,"Delete");
     menu.add(0,3,0,"View");
  return true;
     
    }
    public boolean onOptionsItemSelected(MenuItem item)
    {
     super.onOptionsItemSelected(item);
     Intent myIntent=new Intent(this,InsertActivity.class);
  myIntent.putExtra("label",item.getItemId());
     if(item.getItemId()==0)
     {
   this.startActivity(myIntent);
     }
     else if(item.getItemId()==1)
     {
      this.startActivity(myIntent);
     }
     else if(item.getItemId()==2)
     {
      this.startActivity(myIntent);
     }
     else if(item.getItemId()==3)
     {
      this.startActivity(myIntent);
     }
     
  return true;
     
    }
}
InsertActivity.java
package vc.dataBase;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class InsertActivity extends Activity implements OnClickListener, TextWatcher, OnItemClickListener {
    /** Called when the activity is first created. */
 //Control Declaration
 EditText txtname,txtage,txtphone;
 Button btnSubmit,btnClear;
 TextView lblname,lblage,lblphone,lblmsg;
 ListView list;
 
 //Variable Declaration
 boolean duplicate=true;
 int flag,len=0,count=0;
 String record[];
 String sname;
 
 //DataBase Object Declaration
 SQLiteDatabase db;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.insert);
        db=openOrCreateDatabase("Data",SQLiteDatabase.CREATE_IF_NECESSARY,null);
        
        txtname=(EditText) findViewById(R.id.txtname);
        txtage=(EditText) findViewById(R.id.txtage);
        txtphone=(EditText) findViewById(R.id.txtphone);
        
        lblname=(TextView) findViewById(R.id.lblname);
        lblage=(TextView) findViewById(R.id.lblage);
        lblphone=(TextView) findViewById(R.id.lblphone);
        lblmsg=(TextView) findViewById(R.id.lblmsg);
        list=(ListView) findViewById(R.id.list);
        list.setOnItemClickListener(this);
        
        btnSubmit=(Button) findViewById(R.id.btnSumit);
        btnClear=(Button) findViewById(R.id.btnClear);
        
        Intent intent=getIntent();
  flag=intent.getIntExtra("label", 0);
  
     btnSubmit.setOnClickListener(this);
     btnClear.setOnClickListener(this);
     txtname.requestFocus();
     list.setVisibility(-1);
     lblmsg.setVisibility(-1);
  
     if(flag==1)
  {
   invisible();
   txtname.addTextChangedListener(this);
   btnSubmit.setText("Edit");
   btnClear.setText("Cancel");
   list.setVisibility(0);
  }
  else if(flag==2)
  {
   invisible();
   txtname.addTextChangedListener(this);
   btnSubmit.setText("Delete");
   btnClear.setText("Cancel");
   list.setVisibility(0);
  }
  else if(flag==3)
  {
   View_Records();
  }
     }
    //Method Declaration
    public void invisible()
 {
     lblage.setVisibility(-1);
  lblphone.setVisibility(-1);
  txtage.setVisibility(-1);
  txtphone.setVisibility(-1);
  btnSubmit.setVisibility(-1);
  btnClear.setVisibility(-1);
 }
    public void visible()
    {
     lblage.setVisibility(0);
  lblphone.setVisibility(0);
  txtage.setVisibility(0);
  txtphone.setVisibility(0);
  btnSubmit.setVisibility(0);
  btnClear.setVisibility(0);
 }
    public void DisEnable()
    {
     txtname.setEnabled(false);
     txtage.setEnabled(false);
     txtphone.setEnabled(false);
    }
    public void Enable()
    {
     txtname.setEnabled(true);
     txtage.setEnabled(true);
     txtphone.setEnabled(true);
    }
    public void clear()
 {
  txtname.setText("");
  txtage.setText("");
  txtphone.setText("");
  txtname.requestFocus();
 }
    public void View_Records()
    {
     list.setVisibility(0);
     lblmsg.setVisibility(0);
     invisible();
     txtname.setVisibility(-1);
     lblname.setVisibility(-1);
     
     int i=0;
     Cursor cur=db.rawQuery("select *from Student",null);
     len=cur.getCount();
     record=new String[len];
     if(len>0)
  {
   while(cur.moveToNext())
   {
    record[i]=cur.getString(0)+"  |  "+cur.getString(1)+"  |  "+cur.getString(3);
    i++;
   }
  }
     
     ArrayAdapter<String> arr=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,record);
     list.setAdapter(arr);
    }
    //Control Method
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action=(Button) v;
  duplicate=true;
  if(action.getText().toString().equals("Submit")) //Record Insert
  {   
   if((txtname.getText().toString().equals(""))&&(txtage.getText().toString().equals(""))&&(txtphone.getText().toString().equals("")))
   {
    Toast.makeText(this,"Record is Already Empty",Toast.LENGTH_SHORT).show();
   }
   else if((txtname.getText().toString().equals("")))
   {
    Toast.makeText(this,"Please Enter Name",Toast.LENGTH_SHORT).show();
   }
   else if((txtage.getText().toString().equals("")))
   {
    Toast.makeText(this,"Please Enter Age",Toast.LENGTH_SHORT).show();
   }
   else if((txtphone.getText().toString().equals("")))
   {
    Toast.makeText(this,"Please Enter Phone Number",Toast.LENGTH_SHORT).show();
   }
   else //Duplicate Record
   {
    String name=txtname.getText().toString();
    String phone=txtphone.getText().toString();
    Cursor c;
    if((c=db.rawQuery("select *from Student where name='"+name+"'", null))!=null)
    {
     if(c.getCount()>0)
     {
      duplicate=false;
      Toast.makeText(this,"Name Already Exist ",Toast.LENGTH_SHORT).show();
     }
    }
    if((c=db.rawQuery("select *from Student where phone='"+phone+"'", null))!=null)
    {
     if(c.getCount()>0)
     {
      duplicate=false;
      Toast.makeText(this,"Number Already Exist ",Toast.LENGTH_SHORT).show();
     }
    }
    if(duplicate==true)
    {
     int age=Integer.parseInt(txtage.getText().toString());
     db.execSQL("insert into Student(name,age,phone)values('"+name+"',"+age+",'"+phone+"')");
     clear();
     Toast.makeText(this,"Record Add SuccessFully",Toast.LENGTH_SHORT).show();
    }
    
   }
  }
  else if(action.getText().toString().equals("Clear")) //Clear Field
  {
   if(!((txtname.getText().toString().equals(""))&&(txtage.getText().toString().equals(""))&&(txtphone.getText().toString().equals(""))))
   {
    clear();
   }
   else
   {
    Toast.makeText(this,"Record is Already Empty",Toast.LENGTH_SHORT).show();
   }
  }
  else if(action.getText().toString().equals("Edit")) //Edit Record
  {
   Enable();
   btnSubmit.setText("Save");
  }
  else if(action.getText().toString().equals("Save")) //After Edit Record or Check Duplicate Record 
  {
   String name=txtname.getText().toString();
   String phone=txtphone.getText().toString();
   Cursor c;
   if((c=db.rawQuery("select *from Student where name='"+name+"'and phone='"+phone+"'", null))!=null)
   {
    if(c.getCount()>0)
    {
     duplicate=false;
     Toast.makeText(this,"Duplicate Name Not Allow ",Toast.LENGTH_SHORT).show();
    }
   }
   else if((c=db.rawQuery("select *from Student where phone='"+phone+"'and name!='"+name+"'", null))!=null)
   {
    if(c.getCount()>0)
    {
     duplicate=false;
     Toast.makeText(this,"Duplicate Number Not Allow ",Toast.LENGTH_SHORT).show();
    }
   }
   if(duplicate==true)
   {
    int age=Integer.parseInt(txtage.getText().toString());
    db.execSQL("update Student set name='"+name+"',age="+age+",phone='"+phone+"' where name='"+sname+"';");
    Toast.makeText(this,"Record Update Successfully",Toast.LENGTH_SHORT).show();
    btnSubmit.setText("Submit");
    this.startActivity(new Intent(this,DataBaseActivity.class));
   }
  }
  else if(action.getText().toString().equals("Cancel")) //Cancel Record and Move First Screen
  {
   this.startActivity(new Intent(this,DataBaseActivity.class));
  }
  else if(action.getText().toString().equals("Delete")) //Delete Particular Record
  {
   String name=txtname.getText().toString();
   db.execSQL("delete from Student where name='"+name+"';");
   Toast.makeText(this,"Delete Record Successfully",Toast.LENGTH_SHORT).show();
   this.startActivity(new Intent(this,DataBaseActivity.class));
  }
 }
 //Edit Text Method
 @Override
 public void afterTextChanged(Editable arg0) { //Filtering the Record
  // TODO Auto-generated method stub
  String name=txtname.getText().toString();
  Cursor cur=db.rawQuery("select *from Student where name LIKE '"+name+"%'", null);
  len=cur.getCount();
  if(txtname.getText().toString().equals(""))
  {
   Toast.makeText(this,"Enter Name"+count,Toast.LENGTH_SHORT).show();
   list.setAdapter(null);
   for(int i=0; i<count; i++)
    record[i]="";
  }
  else if(len>0)
  {
   if(txtname.getText().toString().equals(""))
   {
    list.setAdapter(null);
    for(int i=0; i<count; i++)
     record[i]="";
   }
   else if(len>0)
   {
    record=new String[len];
    cur.moveToNext();
    count=len;
    for(int i=0; i<len; i++)
    {
     record[i]=cur.getString(1);
     cur.moveToNext();
    }
   }
   ArrayAdapter<String> arr =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,record);
   list.setAdapter(arr);
 }
 else
 {
  Toast.makeText(this,"Record Not Found",Toast.LENGTH_SHORT).show();
 }
 }
 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onItemClick(AdapterView<?> p, View v, int pos, long s) {
  // TODO Auto-generated method stub
  list.setVisibility(-1);
  visible();
  sname=record[pos];
  Cursor c=db.rawQuery("select *from Student",null);
  int len1=c.getCount();
  if(len1>0)
  {
   while(c.moveToNext())
   {
    if(sname.equals(c.getString(1)))
    {
     txtname.setText(c.getString(1));
     txtage.setText(c.getInt(2)+"");
     txtphone.setText(c.getString(3));
     break;
    }
    DisEnable();
    list.setVisibility(-1);
   }
  }
 }
}

Create an application that will play a media file from the memory card.

PRO17Activity.java
Note :  Drop Audios on Sdcard then go to menus open "Dev-Tools" -> "Media Scanner"
package vc.PRO17;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.MediaStore.Audio.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class PRO17Activity extends Activity implements OnClickListener, OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 Button btnpre,btnstart,btnnext;
 String song[];
 MediaPlayer player;
 ListView lv;
 boolean flag=false;
 static int j=0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnpre=(Button) findViewById(R.id.btnpre);
        btnstart=(Button) findViewById(R.id.btnstart);
        btnnext=(Button) findViewById(R.id.btnnext);
        lv=(ListView) findViewById(R.id.list);
        
        btnpre.setOnClickListener(this);
        btnstart.setOnClickListener(this);
        btnnext.setOnClickListener(this);
        lv.setOnItemClickListener(this);
        btnpre.setTextColor(Color.GREEN);
        btnstart.setTextColor(Color.GREEN);
        btnnext.setTextColor(Color.GREEN);
        try
        {
         Cursor cur=managedQuery(Media.EXTERNAL_CONTENT_URI, null, null, null, null);
         song=new String[cur.getCount()];
         int i=0;
         while(cur.moveToNext())
         {
          song[i]=cur.getString(1).substring(12);
          i++;
         }
         ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,song);
         lv.setAdapter(aa);
        }
        catch(Exception e)
        {
         Toast.makeText(this,e.toString(),1).show();
        }
    }
    public void song_play()
    {
     try
     {
      if(flag==true)
       player.stop();
      player=new MediaPlayer();
   player.setDataSource("/sdcard/"+song[j]);
      player.prepare();
   player.start();
   flag=true;
  }
     catch(Exception e)
  {
   Toast.makeText(this,"Play"+j, 1).show();
  }
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action =(Button) v;
  if(v.getId()==btnpre.getId())
  {
   if(j>0)
   {
    j--;
    song_play();
   }
   else
   {
    song_play();
   }
   
  }
  else if(action.getText().toString().equals("|>"))
  {
   song_play();
   btnstart.setBackgroundResource(R.drawable.pause);
   btnstart.setText("||");
  }
  else if(action.getText().toString().equals("||"))
  {
   player.stop();
   btnstart.setBackgroundResource(R.drawable.play);
   btnstart.setText("|>");
  }
  else if(v.getId()==btnnext.getId())
  {
   if(song.length-1>j)
   {
    j++;
    song_play();
   }
   else
   {
    song_play();
   }
  }
 }
 @Override
 public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
  // TODO Auto-generated method stub
  j=arg2;
  song_play();
  btnstart.setText("||");
  btnstart.setBackgroundResource(R.drawable.pause);
 }
}

Create an application to read file from asset folder and copy it in memory card.

Pro16Activity.java
package ps.pro16;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class Pro16Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 TextView tvmsgfromasset,tvmsgfromsdcard;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        try 
        {
         tvmsgfromasset=(TextView) findViewById(R.id.textView2);
            tvmsgfromsdcard=(TextView) findViewById(R.id.textView4);
            
   //--------reading from asset folder-----------
         
         InputStream is1=null;     
   is1=getResources().getAssets().open("hello.txt");
   
   if(is1!=null)
   {

    Toast.makeText(this, "File Exists", Toast.LENGTH_LONG).show();
    
    String myMsg1="";
    while(is1.available()>0)
    {
     myMsg1=myMsg1+(char)is1.read();
    }
    is1.close();
    
    tvmsgfromasset.setText(myMsg1);
    
   //--------writing to sdcard-----------
    
    byte b[]=myMsg1.getBytes();
    File myFile = new File("/sdcard/hello.txt");
    OutputStream os=new FileOutputStream(myFile);
    os.write(b);
    os.close();
    Toast.makeText(this, "write Success.", Toast.LENGTH_LONG).show();
    
   //--------read file from sdcard--------
    
    InputStream is2=null;
    is2=new FileInputStream(myFile);
    String myMsg2="";
    while(is2.available()>0)
    {
     myMsg2=myMsg2+(char)is2.read();
    }
    is2.close();
    tvmsgfromsdcard.setText(myMsg2+"");
   }
  } 
        catch (IOException e) 
        {
   Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
  }
    }
}

Create an application that will create database with table of User credential.

PRO15Activity.java
package vc.PRO15;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class PRO15Activity extends Activity implements OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
 ListView lv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db=openOrCreateDatabase("database1",SQLiteDatabase.CREATE_IF_NECESSARY, null);
  db.execSQL("create table if not exists stud(id integer primary key AUTOINCREMENT,name text,age integer)");
  lv =(ListView) findViewById(R.id.list);
  lv.setOnItemClickListener(this);
  Cursor cur=db.query("stud",null, null, null, null, null, null);
  
  if(cur.getCount()>0)
  {
   String name[]=new String[cur.getCount()];
   int i=0;
   while(cur.moveToNext())
   {
    name[i++]=cur.getString(1);
   }
   ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,name);
   lv.setAdapter(aa);
  }
  else
  {
         Toast.makeText(this,"DataBase is Empty...", 1000).show();
  }
    }
 @Override
 public void onItemClick(AdapterView p, View v, int pos, long c) {
  // TODO Auto-generated method stub
  Intent myintent=new Intent(this,update.class);
  TextView iname=(TextView) v;
  myintent.putExtra("label",iname.getText().toString() );
  startActivity(myintent);
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  super.onCreateOptionsMenu(menu);
  menu.add(0,5,0,"Insert");
  menu.add(0,1,0,"Update");
  menu.add(0,2,0,"Delete");
  return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
   super.onOptionsItemSelected(item);
   if(item.getItemId()==5)
   {
    Intent myintent=new Intent(this,update.class);
    myintent.putExtra("flag",item.getItemId());
    startActivity(myintent);
   } 
   else if(item.getItemId()==1)
   {
    Intent myintent=new Intent(this,update.class);
    myintent.putExtra("flag",item.getItemId());
    startActivity(myintent);
   }
   else  if(item.getItemId()==2)
   {
    Intent myintent=new Intent(this,update.class);
    myintent.putExtra("flag",item.getItemId());
    startActivity(myintent);
   }
   return true;
 }
}
insert.java
package vc.PRO15;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

public class insert extends Activity  {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db=openOrCreateDatabase("database1",SQLiteDatabase.CREATE_IF_NECESSARY, null);
  db.execSQL("create table if not exists stud(id integer primary key,name text,age integer)");
    }
}
update.java
package vc.PRO15;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class update extends Activity implements OnClickListener, TextWatcher, OnItemClickListener  {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 SQLiteDatabase db;
 EditText txtname,txtage,txtid;
 Button btnedit,btncancel;
 TextView lblage;
 ListView lv;
 String name[];
 int flag=-1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update);
        db=openOrCreateDatabase("database1",SQLiteDatabase.CREATE_IF_NECESSARY, null);
  db.execSQL("create table if not exists stud(id integer primary key AUTOINCREMENT,name text,age integer)");
  
  lblage=(TextView) findViewById(R.id.textView2);
  txtname=(EditText) findViewById(R.id.txtname);
  txtage=(EditText) findViewById(R.id.txtage);
  txtid=(EditText) findViewById(R.id.txtid);
  btnedit=(Button) findViewById(R.id.btnedit);
  btncancel=(Button) findViewById(R.id.btncancel);
  
  lv=(ListView) findViewById(R.id.list);
  lv.setVisibility(-1);
  txtid.setVisibility(-1);
  Intent myintent=getIntent();
  flag=myintent.getIntExtra("flag", 0);
  if(flag==0)
  {
   try
   {
    String label=myintent.getStringExtra("label");
    Cursor cur=db.query("stud",null,"name=?",new String []{label},null, null,null);
    cur.moveToFirst();
    Toast.makeText(this,cur.getString(0)+"", 1).show();
    txtid.setText(cur.getString(0)+"");
    txtname.setText(cur.getString(1));
    txtage.setText(cur.getString(2));
    btnedit.setText("Update");
    txtage.setEnabled(true);
   }
   catch(Exception e)
   {
    Toast.makeText(this,e.toString(), 1).show();
   }
  }
  else if(flag==1)
  {
   txtname.addTextChangedListener(this);
   lv.setVisibility(0);
   invisible();
   txtage.setEnabled(false);
  }
  else if(flag==2)
  {
   txtname.addTextChangedListener(this);
   lv.setVisibility(0);
   invisible();
   btnedit.setText("Delete");
  }
  else if(flag==5)
  {
   btnedit.setText("Save");
  }
  btnedit.setOnClickListener(this);
  btncancel.setOnClickListener(this);
  lv.setOnItemClickListener(this);
    }
    public void invisible()
    {
     lblage.setVisibility(-1);
     txtage.setVisibility(-1);
     btncancel.setVisibility(-1);
     btnedit.setVisibility(-1);
    }
    public void visible()
    {
     lblage.setVisibility(0);
     txtage.setVisibility(0);
     btncancel.setVisibility(0);
     btnedit.setVisibility(0);
    }
    public void clear()
    {
     txtid.setText("");
     txtname.setText("");
     txtage.setText("");
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  Button action=(Button) v;
  if(action.getText().toString().equals("Edit"))
  {
   txtage.setEnabled(true);
   btnedit.setText("Update");
  }
  else if(action.getText().toString().equals("Update"))
  {
   ContentValues value=new ContentValues();
   value.put("name", txtname.getText().toString());
   value.put("age",txtage.getText().toString());
   db.update("stud",value, "id=?", new String[]{txtid.getText().toString()});
   btnedit.setText("Edit");
   Toast.makeText(this,"Update Successfully",1000).show();
   startActivity(new Intent(this,PRO15Activity.class));
  }
  else if(action.getText().toString().equals("Delete"))
  {
   db.delete("stud", "id=?",new String[]{txtid.getText().toString()});
   Toast.makeText(this, "Record Deleted...", Toast.LENGTH_LONG).show();
   startActivity(new Intent(this,PRO15Activity.class));
  }
  else if(action.getText().toString().equals("Save"))
  {
   if(txtname.getText().toString().equals(""))
   {
    Toast.makeText(this,"Please Enter Name ...", 1).show();
   }
   else if(txtage.getText().toString().equals(""))
   {
    Toast.makeText(this,"Please Enter Age ...", 1).show();
   }
   else
   {
    try
    {
     Cursor cur=db.query("stud", null, "name=?",new String[]{txtname.getText().toString()},null, null,null);
     if(cur.getCount()>0)
     {
      Toast.makeText(this,"Name Allready Exists ...",1).show();
     }
     else
     {
       ContentValues values=new ContentValues();
       values.put("name", txtname.getText().toString());
       values.put("age",txtage.getText().toString());
       db.insert("stud",null, values);
       Toast.makeText(this,"Record Saved...", 1).show();
     }
    }
    catch(Exception e)
    {
     Toast.makeText(this,e.toString(), 1).show();
    }
   }
  }
  else if(v.getId()==btncancel.getId())
  {
   startActivity(new Intent(this,PRO15Activity.class));
  }
 }
 public void enabled()
 {
  txtage.setEnabled(true);
 }
 public void disabled()
 {
  txtage.setEnabled(false);
 }
 @Override
 public void afterTextChanged(Editable arg0) {
  // TODO Auto-generated method stub
  Cursor cur=db.rawQuery("select *from stud where name like '"+txtname.getText().toString()+"%'",null);
  int len=cur.getCount();
  try
  {
   if(txtname.getText().toString().equals(""))
   {
    lv.setAdapter(null);
    name[0]="";
   }
   else if(len>0)
   {
    if(txtname.getText().toString().equals(""))
    {
     lv.setAdapter(null);
     for(int i=0; i<len; i++)
      name[i]="";
    }
    else if(len>0)
    {
     name=new String[len];
     cur.moveToNext();
     for(int i=0; i<len; i++)
     {
      name[i]=cur.getString(1);
      cur.moveToNext();
     }
    }
    ArrayAdapter<String> aa=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,name);
    lv.setAdapter(aa);
   }
   else
   {
    Toast.makeText(this,"Recoerd Not Found...", 1000).show();
   }
  }
  catch(Exception e)
  {
   Toast.makeText(this,e.toString(),1000).show();
  }
 }
 @Override
 public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
   int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
  // TODO Auto-generated method stub
 }
 @Override
 public void onItemClick(AdapterView<?> p, View v, int pos, long c) {
  // TODO Auto-generated method stub
  TextView iname=(TextView) v;
  String sname=iname.getText().toString();
  
  Cursor cur=db.rawQuery("select *from stud",null);
  if(cur.getCount()>0)
  {
   while(cur.moveToNext())
   {
    if(sname.equals(cur.getString(1)))
    {
     txtid.setText(cur.getInt(0)+"");
     txtname.setText(cur.getString(1));
     txtage.setText(cur.getString(2));
     break;
    }
   }
   visible();
   lv.setVisibility(-1);
  }
 }
}