我试图阅读接触表的接触,将其全部储存在一份清单中,但无法说明为什么它似乎在发挥作用,而是把一支部队放在执行上。 这些接触需要从json物体上送到一个网络服务器。
private static final String TABLE_CONTACTS = "contacts";
// contacts JSONArray
JSONArray contacts = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<contact> l=new ArrayList<contact>();
String query="SELECT * FROM"+ TABLE_CONTACTS;
DBHelper help= new DBHelper(getBaseContext());
SQLiteDatabase db=help.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
if(cursor.moveToFirst())
{
do{
contact contact = new contact();
contact.setID(Integer.parseInt(cursor.getString(0)));
contact.setName(cursor.getString(1));
contact.setPhoneNumber(cursor.getString(2));
Toast.makeText(this,contact.name,Toast.LENGTH_LONG);
l.add(contact);
iii
while(cursor.moveToNext());
iii
单体档案有2份许可
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
以及利用BDBHelper班来扩大Sqlit openhelper,以获得可燃的Database。
class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "contactsManager";
// Contacts table name
private static final String TABLE_CONTACTS = "contacts";
DBHelper(Context context) {
super(context,DATABASE_NAME, null,1);
iii
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
iii
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
iii
iii