private boolean queryChannelFromDatabase() { MmsLog.d(LOG_TAG, "queryChannelFromDatabase start"); clearChannel(); String[] projection = new String[] {KEYID, NAME, NUMBER, ENABLE}; Cursor cursor = null; try { cursor = this.getContentResolver().query(mUri, projection, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { CellBroadcastChannel channel = new CellBroadcastChannel(); channel.setChannelId(cursor.getInt(2)); channel.setKeyId(cursor.getInt(0)); channel.setChannelName(cursor.getString(1)); channel.setChannelState(cursor.getInt(3) == 1); mChannelArray.add(channel); } } } catch (IllegalArgumentException e) { return false; } finally { cursor.close(); } MmsLog.d(LOG_TAG, "queryChannelFromDatabase end"); return true; }
private boolean insertChannelToDatabase(CellBroadcastChannel channel) { ContentValues values = new ContentValues(); values.put(NAME, channel.getChannelName()); values.put(NUMBER, channel.getChannelId()); values.put(ENABLE, channel.getChannelState()); try { Uri uri = getContentResolver().insert(mUri, values); int insertId = Integer.valueOf(uri.getLastPathSegment()); channel.setKeyId(insertId); MmsLog.d(LOG_TAG, "insertChannelToDatabase(), insertId: " + insertId); } catch (IllegalArgumentException e) { return false; } return true; }