• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps null value in Conentprovider

Hi all,

I trying to use existing contentprovider ie Contact.

I am adding number and name and fetch the contact details and display. But everytime i will get number as null.

My code runs as follows

public class MyContactProviderAcitivity extends Activity {
/** Called when the activity is first created. */

Button IB;
Button DB;
Button INSB;
TextView TV;

//LinearLayout ll;
Uri u;

String proj[]=new String[]{People.NUMBER, People.NAME};


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
u=People.CONTENT_URI;
IB= (Button) findViewById(R.id.Ib);
DB=(Button) findViewById(R.id.Db);
INSB=(Button) findViewById(R.id.INSB);
TV=(TextView) findViewById(R.id.TV);

addevents();
}

public void addevents()

{
System.out.println("In Addevents");

INSB.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

ContentValues cv=new ContentValues();
cv.put(People.NAME, "Sita");
Uri resuri=getContentResolver().insert(u, cv);


cv.clear();
Uri details=Uri.withAppendedPath(resuri, People.Phones.CONTENT_DIRECTORY);

cv.put(People.Phones.NUMBER, "23423");
cv.put(People.Phones.TYPE,People.Phones.TYPE_MOBILE);
getContentResolver().insert(details, cv);

}
});


IB.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

String str="";
LinearLayout ll=(LinearLayout) findViewById(R.id.root);


ll.removeView(TV);
Cursor c=ViewData();
c.moveToFirst();
while (!c.isAfterLast())
{
str=str+c.getString(c.getColumnIndex(People.NAME))+c.getString(c.getColumnIndex(People.NUMBER));
c.moveToNext();
}

TV.setText(str);
ll.addView(TV);
}
});



DB.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
int i=getContentResolver().delete(u, "People.NAME='Sita'", null);


}
});

}

public Cursor ViewData()
{
//ContentResolver cr=getContentResolver();
Cursor c=getContentResolver().query(u, proj, null, null, null);
return c;
}

}

Have specified contacts read, write permission in manifest file.

Can anyone tell where i am going wrong.

Thanks in advance,
Pavan
 
Back
Top Bottom