Pages

Tuesday, 17 April 2012

Learning Content Provider

Following code show how to read contacts and sms from our phone.


package com.myphonebook;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class MyPhoneBookActivity extends Activity implements OnClickListener {
Button btnPhone,btnSMS;
ListView lv;
SimpleCursorAdapter adp;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        btnSMS = (Button) findViewById(R.id.btnSMS);
       
        btnPhone = (Button) findViewById(R.id.btnPhone);
        btnPhone.setOnClickListener(this);
        btnSMS.setOnClickListener(this);
    }
@Override
public void onClick(View v) {

if(v==btnPhone)
{
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if(cur.getCount()>0)
{
while(cur.moveToNext())
{
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if(Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))>0)
{
Cursor c = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null);
while(c.moveToNext())
{
String phone = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.d("My Phone Book", " Name : "+name + " Phone : "+phone);
}
}
}
}


}
if(v==btnSMS)
{
Cursor c =  getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
String[] nm = new String[]{"body"};
int[] id = new int[]{R.id.lblMsg};

adp = new SimpleCursorAdapter(this, R.layout.row, c, nm, id);
lv.setAdapter(adp);
}
}
}

Expandable Listview In Andrpod

This may help u in your apps.it show expandable listview of android.



package com.expandablelistview;

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;

public class ExpandablelistviewActivity extends ExpandableListActivity
{
 /**
  * strings for group elements
  */
    static final String arrGroupelements[] =
    {
   "India",
   "Australia",
   "England",
   "South Africa"
 };

    /**
  * strings for child elements
  */
 static final String arrChildelements[][] =
 {
   {
  "Sachin Tendulkar",
  "Raina",
  "Dhoni",
  "Yuvi"
   },
   {
  "Ponting",
  "Adam Gilchrist",
  "Michael Clarke"
   },
   {
  "Andrew Strauss",
  "kevin Peterson",
  "Nasser Hussain"
   },
   {
  "Graeme Smith",
  "AB de villiers",
  "Jacques Kallis"
   }
    };

 DisplayMetrics metrics;
 int width;
 ExpandableListView expList;
 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        expList = getExpandableListView();
        metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        width = metrics.widthPixels;
        //this code for adjusting the group indicator into right side of the view
        expList.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10));
        expList.setAdapter(new ExpAdapter(this));
 
  expList.setOnGroupExpandListener(new OnGroupExpandListener()
  {
   public void onGroupExpand(int groupPosition)
   {
    Log.e("onGroupExpand", "OK");
   }
  });
 
  expList.setOnGroupCollapseListener(new OnGroupCollapseListener()
  {
   public void onGroupCollapse(int groupPosition)
   {
    Log.e("onGroupCollapse", "OK");
   }
  });
 
  expList.setOnChildClickListener(new OnChildClickListener()
  {
   public boolean onChildClick(ExpandableListView parent, View v,
     int groupPosition, int childPosition, long id) {
    Log.e("OnChildClickListener", "OK");
    return false;
   }
  });
    }
 
    public int GetDipsFromPixel(float pixels)
    {
     // Get the screen's density scale
     final float scale = getResources().getDisplayMetrics().density;
     // Convert the dps to pixels, based on density scale
     return (int) (pixels * scale + 0.5f);
    }
}

Display All Folder Of Sdcard

This example display all folder of sdcard in listview.see this code..




package com.getallfolder;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class GetallfolderActivity extends Activity
{
ArrayList<String> path = new ArrayList<String>();
ArrayList<String> item = new ArrayList<String>();
ListView lst;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        lst = (ListView)findViewById(R.id.listView1);
        File mfile=new File("/sdcard/");
        File[] list=mfile.listFiles();
     
            for(int i=0; i < list.length; i++)
            {
              File file = list[i];
              path.add(file.getPath());
              if(file.isDirectory())
                   item.add(file.getName()+"/");
              else
              item.add(file.getName());
            }
           
           lst.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,item));
    }
}

Custom Spinner Example

This example shows how to display spinner item with image or what u want.



package com.customspinner;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

public class CustomspinnerActivity extends Activity {
   
    String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
            "Wednesday", "Thursday", "Friday", "Saturday"};
   
    Integer[] image = {
                 R.drawable.one,
                R.drawable.two,
                R.drawable.three,
                R.drawable.four,
                R.drawable.five,
                R.drawable.six,
                R.drawable.seven,
                R.drawable.eight };
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
        mySpinner.setAdapter(new MyCustomAdapter(CustomspinnerActivity.this, R.layout.row, DayOfWeek,image));
    }
   
    public class MyCustomAdapter extends ArrayAdapter<String>{

        public MyCustomAdapter(Context context, int textViewResourceId,
                String[] objects, Integer[] image) {
            super(context, textViewResourceId, objects);
            // TODO Auto-generated constructor stub
        }

        @Override
        public View getDropDownView(int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            return getCustomView(position, convertView, parent);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            return getCustomView(position, convertView, parent);
        }

        public View getCustomView(int position, View convertView, ViewGroup parent) {
   
            LayoutInflater inflater=getLayoutInflater();
            View row=inflater.inflate(R.layout.row, parent, false);
            TextView label=(TextView)row.findViewById(R.id.weekofday);
            label.setText(DayOfWeek[position]);
           
            ImageView icon=(ImageView)row.findViewById(R.id.icon);
            icon.setImageResource(image[position]);
            return row;
        }  
    }
}

Thursday, 12 April 2012

Great Insult:

Girl: Meri ek ek saans per ek ek ladka marta hai...
Boy: Fir tum....











Brush kyu nhi karti...=))



Life Me Kabhi Kisiko Vishvas Dilane ki Zarurat nathi hoti,
Kyuki
"Dushman Kabhi Yakin Nahi Karega" OR
"Dost Kabhi Saq Nahi Karega".
Koik 6e Je Tamne Hamesa Yad Kare 6e,
Koik 6e Je Hamesa tamari Khusi Ichhe 6e,

Bus Aa Koik Male Tyare Tene Apnavi Lejo
Ane Mane Tamara Lagan ma Bolavi Lejo.
Day begins with hopes and ends with a dreams!
Everyday starts with some expectation but
Everyday surely ends with some experience.
That's life.
Khusi nahi to life waste,
Salt nahi to food waste,
Without story cinema waste,
Hamara sms nahi to apka mobile waste,
But apki smile nahi to amara sms waste.

Wednesday, 11 April 2012

Ship is always safe at shore... but is is not built for it

વહાણ દરિયા કિનારે હન્મેશા સલામત હોય છે , પણ એ દરિયા કિનારે રહેવા માટે નથી સર્જાયુ ...આ વાક્ય જીવન મા જોખમો ખેડવાની સલાહ આપે છે , જોખમો ઉઠાવ્યા સિવાય સફળતા નથી મળતી.
Self-trust is the first secret of success
‘મારા બાપા ખરું કહેતા હતા’ એવું માણસને જ્ઞાન થાય છે ત્યાં સુધીમાં તો એનો દીકરો એવું વિચારતો થઈ ગયો હોય છે કે ‘મારા બાપા ખોટા છે.’ – ચાર્લ્સ વર્ડઝવર્થ
જીવન એક બાજી છે, જેમાં હારજીત આપણા હાથમાં નથી, પણ બાજી રમવી આપણા હાથમાં છે.
“If you don’t like something change it;
if you can’t change it,
change the way you think about it.”

Read Data From Assets

This show how to read text file which store in assets folder. Reading all content of file and use it as per your requirement.

Download this File: CLICK HERE

TabHost In Android

This helps you to use tab in your application.use it.


DownLoad This Example: CLICK HERE

Displaying Images From SDCARD

This example display all images from sdcard to listview. You can also store image into database from sdcard.

Download This File: CLICK HERE

Example Of Different Android Views

This file provides small examples of different view of android Like,
view flipper,
view animation,
image switcher,
text swithcer,
gallary,
gridview,
audio recording,
playing audio,
playing video,
sliding drawer,
image move.
etc.....

Download This File: CLICK HERE

Database on server side

This example displays how to store, display and delete record from server side in android.Here i used xampp server.you can use tomcat.

Download This Example:
Java File: CLICK HERE
PHP For Insert File: CLICK HERE
PHP For Delete File: CLICK HERE
PHP For Display File: CLICK HERE

CUSTOM LISTVIEW EXAMPLE

This is the custom list view example in android. This is used to display many items in one row.if u want to display text,images or text,text in a list view then u have to use custom list view in android.

Download CustomListView Example: CLICK HERE

ANDROID EBOOK


You can download android book "Android Wireless Application Development, 2nd edition".It is a easy book for android beginer to developed small application...

For DownlLoad This Book  CLICK HERE

Tuesday, 10 April 2012



“દરેક સફળ માણસની પાછળ એક સ્ત્રી હોય છે”


તથા


“દરેક નિષ્ફળ માણસની પાછળ પણ એક સ્ત્રી જ હોય છે.” !!!

એક સાસુમા ના ૩ જમાઈ હતા.તેમને બધા ની પરીક્ષા લેવાનું નક્કી કર્યું.
એક દિવસ..પેહલા જમાઈ ને બોલાવીને પોતે નદી માં ઝંપલાવી દીધું.પેહલા જમાઈ એ તેમને બચાવી લીધા અને સાસુમા એ તેમને કાર ભેટ માં આપી.
બીજા જમાઈ ને બોલાવીને પણ તેમ જ કર્યું.બીજા જમાઈ એ પણ તેમને બચાવી લીધા અને તેમને સ્કુટર ભેટ આપ્યું.
…..પછી વારો આવ્યો ત્રીજા નો.તેણે વિચાર્યું કે જો હવે આવું થશે તો મને બચેલી સાઈકલ મળશે. તેથી તેણે સાસુમા ને નદી માં ડૂબવા દીધા. તેરમાં ને દિવસે ૩જો જમાઈ નવી હોન્ડા સીટી લઇ ને આવ્યો ત્યારે બીજા ૨ ની આંખો ફાટ ફાટ થઇ રહી..હવે કહો આ હોન્ડા સીટી કોણે અપાવી ??.
.
.
.
.
.સ્વાભાવિક છે યાર….સસરા એ 




Monday, 9 April 2012









હંમેશા હસતા રહેવાથી અને ખુશનુમા રહેવાથી, પ્રાર્થના કરતાં પણ વધારે જલદી ઈશ્વરની નજીક પહોંચાય છે.
–સ્વામી વિવેકાનંદ

Sunday, 8 April 2012

All glory comes from daring to begin
Never mind what others do. Do better than yourself. Try to beat your own records everyday and pray to God for a better tomorrow
Success is more permanent when you achieve it without losing your principles.
WE CAN ALWAYS CHOOSE TO PERCEIVE THINGS DIFFERENTLY. YOU CAN FOCUS ON WHAT’S WRONG IN YOUR LIFE OR YOU CAN FOCUS ON WHAT’S RIGHT
Love is Precious Gift of GOD. Life is full of Love and Joy. We just need to free our inner selves, need more attachment with nature, feel the rhythm of Love and every moment of our Life. If we do so, we can easily touch the soul

You want and you get, that is luck.
You want and you wait and, that is time.
You want but you compromise, that is life.
You want, you wait and you don not compromise that is SUCCESS.

Love is a gift. If you receive it, open and appreciate it.
If not, don not worry. Someone somewhere is still wrapping it for you.
 Luck is not in your hands. But work is in your hands. 
Your works can make your luck but luck can not make your works.
So always trust yourself.