android.app.Activity;
android.database.Cursor;
android.net.Uri;
android.os.Bundle;
android.widget.ArrayAdapter;
android.widget.ListView;
Pro13Activity.java :
package ps.pro13;
import
import
import
import
import
android.app.Activity;
android.database.Cursor;
android.net.Uri;
android.os.Bundle;
android.widget.TextView;
android.app.Activity;
android.content.Intent;
android.net.Uri;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.EditText;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
num=(EditText) findViewById(R.id.editTextnum);
dial=(Button) findViewById(R.id.buttondial);
dial.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==dial.getId())
{
Intent myintent=new Intent(Intent.ACTION_DIAL,
Uri.parse("tel:"+num.getText()));
startActivity(myintent);
}
}
}
15 Create an application that will create database with table of User credential.
PRO15Activity.java :
package vc.PRO15;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
android.app.Activity;
android.content.Intent;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.AdapterView;
android.widget.AdapterView.OnItemClickListener;
android.widget.ArrayAdapter;
android.widget.ListView;
android.widget.TextView;
android.widget.Toast;
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<string> aa=new
ArrayAdapter<string>(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;
}
}
</string></string>
Insert.java :
package vc.PRO15;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
public class insert extends Activity
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
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
android.app.Activity;
android.content.ContentValues;
android.content.Intent;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.os.Bundle;
android.text.Editable;
android.text.TextWatcher;
android.view.View;
android.view.View.OnClickListener;
android.widget.AdapterView;
android.widget.AdapterView.OnItemClickListener;
android.widget.ArrayAdapter;
android.widget.Button;
android.widget.EditText;
android.widget.ListView;
android.widget.TextView;
android.widget.Toast;
}
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"))
{
}
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);
}
}
16 Create an application to read file from asset folder and copy it in memory card.
Pro16Activity.java :
package ps.pro16;
import
import
import
import
import
import
java.io.File;
java.io.FileInputStream;
java.io.FileOutputStream;
java.io.IOException;
java.io.InputStream;
java.io.OutputStream;
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.widget.TextView;
android.widget.Toast;
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();
17 Create an application that will play a media file from the memory card.
PRO17Activity.java :
package vc.PRO17;
import android.app.Activity;
import android.database.Cursor;
import
import
import
import
import
import
import
import
import
import
import
import
android.graphics.Color;
android.media.MediaPlayer;
android.os.Bundle;
android.provider.MediaStore.Audio.Media;
android.view.View;
android.view.View.OnClickListener;
android.widget.AdapterView;
android.widget.AdapterView.OnItemClickListener;
android.widget.ArrayAdapter;
android.widget.Button;
android.widget.ListView;
android.widget.Toast;
song=new String[cur.getCount()];
int i=0;
while(cur.moveToNext())
{
song[i]=cur.getString(1).substring(12);
i++;
}
ArrayAdapter<string> aa=new
ArrayAdapter<string>(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);
}
}
</string></string>
18 Create an application to make Insert , update , Delete and retrieve operation on the
database.
DataBaseActivity.java :
package vc.dataBase;
import
import
import
import
import
import
android.app.Activity;
android.content.Intent;
android.database.sqlite.SQLiteDatabase;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
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;
}
19 Create an application to read file from the sdcard and display that file content to the
screen.
Pro19Activity.java :
package ps.pro19;
import
import
import
import
import
import
import
java.io.File;
java.io.FileInputStream;
java.io.InputStream;
android.app.Activity;
android.os.Bundle;
android.widget.TextView;
android.widget.Toast;
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();
}
20 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 {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ScreenActivity(this));
}
}<span style="color: #0b5394;"><b>
</b></span>
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;
}
}
Pro21Activity.java :
package ps.pro21;
import
import
import
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.telephony.gsm.SmsManager;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.EditText;
Pro22Activity.java :
Note: Give permission in manifest file as "android.permission.CAMERA"
package ps.pro22;
import android.app.Activity;
import android.content.Intent;
import
import
import
import
import
import
android.graphics.Bitmap;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.ImageView;
23 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
import
import
import
import
import
import
import
import
android.net.Uri;
android.os.Bundle;
android.provider.MediaStore.Images.Media;
android.util.Log;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.ImageView;
android.widget.Toast;
}
@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);
}
}
24 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
import
import
import
import
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.view.View;
android.view.View.OnClickListener;
android.webkit.WebView;
android.webkit.WebViewClient;
android.widget.Button;
android.widget.TextView;
android.widget.Toast;
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://") &&
stringurl.startsWith("https://") )
stringurl="http://"+stringurl;
}
}