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

Thursday, 18 October 2012

Understanding content providers and permissions:
a. Read phonebook contacts using content providers and display in list.

Pro12Activity.java
Note:Give "READ_CONTACTS" permission in android Manifest file.
package ps.pro12;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Pro12Activity extends Activity {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView mylist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mylist=(ListView) findViewById(R.id.listView1);
        
        //Uri u=Uri.parse("content://contacts/people");
        Uri u=Phones.CONTENT_URI;
        Cursor cur=managedQuery(u, null,null,null,null);
        
        String names[]=new String[cur.getCount()];
        
        int i=0;
        while(cur.moveToNext())
        {
         names[i++]=cur.getString(15)+"ntttt"+cur.getString(7);
        }
        
        ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,names);
        mylist.setAdapter(aa);
    }
}

No comments:

Post a Comment