WEB开发网
开发学院手机开发Android 开发 Android content provider基础与使用 阅读

Android content provider基础与使用

 2010-08-21 06:22:00 来源:WEB开发网   
核心提示:ContentResolver cr = getContentResolver();//Cursor cur = managedQuery(People.CONTENT_URI, null, null, null, null);Cursor cur = cr.query(People.CONTENT_URI, null

ContentResolver cr = getContentResolver();

//Cursor cur = managedQuery(People.CONTENT_URI, null, null, null, null);

Cursor cur = cr.query(People.CONTENT_URI, null, null, null, null);

getColumnData(cur);

}

private void getColumnData(Cursor cur){

if (cur.moveToFirst()) {

String name;

String phoneNumber;

int nameColumn = cur.getColumnIndex(People.NAME);

int phoneColumn = cur.getColumnIndex(People.NUMBER);

do {

// Get the field values

name = cur.getString(nameColumn);

phoneNumber = cur.getString(phoneColumn);

Log.i(TAG, "name="+name);

DisplayToast(name+" "+phoneNumber);

} while (cur.moveToNext());

}

}

public void DisplayToast(String s)

{

Toast.makeText(this,

s,

Toast.LENGTH_LONG).show();

}

}

需要注意的是,你需要在你的Manifest文件中加上

< uses-permission

android:name="android.permission.READ_CONTACTS">

< /uses-permission>

否则,程序无法成功运行。

上一页  1 2 

Tags:Android content provider

编辑录入:coldstar [复制链接] [打 印]
赞助商链接