List of usage examples for android.database Cursor getCount
int getCount();
From source file:edu.pdx.cecs.orcycle.NoteUploader.java
@Override protected Boolean doInBackground(Long... noteIds) { // First, send the note user asked for: Boolean result = true;/* w ww . j a va 2s .c o m*/ if (noteIds.length != 0) { result = uploadOneNote(noteIds[0]); } // Then, automatically try and send previously-completed notes // that were not sent successfully. Vector<Long> unsentNotes = new Vector<Long>(); mDb.openReadOnly(); Cursor cur = mDb.fetchUnsentNotes(); if (cur != null && cur.getCount() > 0) { // pd.setMessage("Sent. You have previously unsent notes; submitting those now."); while (!cur.isAfterLast()) { unsentNotes.add(Long.valueOf(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long note : unsentNotes) { result &= uploadOneNote(note); } return result; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
public static int getUnNotifyUnreadCount() { String sql = "SELECT sum(" + IThreadColumn.UNREAD_COUNT + ") FROM im_thread \n" + " inner JOIN groups2 ON im_thread.sessionId = groups2.groupid and isnotice == 2"; int count = 0; Cursor cursor = null; try {//w ww . j a va 2 s . c o m cursor = getInstance().sqliteDB().rawQuery(sql, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { count = cursor.getInt(cursor.getColumnIndex("sum(" + IThreadColumn.UNREAD_COUNT + ")")); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); } } return count; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
public static ECMessage getMsg(String id) { String sql = "select * from " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " where msgid = '" + id + "'"; Cursor cursor = null; try {// w w w.j ava2 s . c o m cursor = getInstance().sqliteDB().rawQuery(sql, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { return packageMessage(cursor); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); cursor = null; } } return null; }
From source file:eu.codeplumbers.cosi.services.CosiSmsService.java
private void readSmsDatabase() { //Fetches the complete call log in descending order. i.e recent calls appears first. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED) { Uri message = Uri.parse("content://sms/"); ContentResolver cr = getContentResolver(); Cursor c = cr.query(message, null, null, null, null); int totalSMS = c.getCount(); if (c.moveToFirst()) { for (int i = 0; i < totalSMS; i++) { mBuilder.setProgress(totalSMS, i, false); mNotifyManager.notify(notification_id, mBuilder.build()); EventBus.getDefault()/* www . j a v a 2 s.c o m*/ .post(new SmsSyncEvent(SYNC_MESSAGE, getString(R.string.lbl_sms_status_read_phone))); String systemId = c.getString(c.getColumnIndexOrThrow("_id")); String address = c.getString(c.getColumnIndexOrThrow("address")); String body = c.getString(c.getColumnIndexOrThrow("body")); String readState = c.getString(c.getColumnIndex("read")); String dateAndTime = c.getString(c.getColumnIndexOrThrow("date")); String type = c.getString(c.getColumnIndexOrThrow("type")); Sms sms = Sms.getBySystemId(systemId); if (sms == null) { sms = new Sms(); sms.setRemoteId(""); } sms.setBody(body); sms.setAddress(address.replace(" ", "").replace("-", "")); sms.setDateAndTime(DateUtils.formatDate(dateAndTime)); sms.setSystemId(systemId); sms.setType(Integer.valueOf(type)); sms.setReadState(Boolean.parseBoolean(readState)); sms.setDeviceId( sms.getRemoteId() != "" ? sms.getDeviceId() : Device.registeredDevice().getLogin()); sms.save(); allSms.add(sms); c.moveToNext(); } } // else { // throw new RuntimeException("You have no SMS"); // } c.close(); } else { EventBus.getDefault().post(new SmsSyncEvent(SERVICE_ERROR, getString(R.string.permission_denied_sms))); stopSelf(); } }
From source file:fr.unix_experience.owncloud_sms.engine.SmsFetcher.java
public void bufferizeMessagesSinceDate(MailboxID mbID, Long sinceDate) { String mbURI = mapMailboxIDToURI(mbID); if (_context == null || mbURI == null) { return;//from w w w . j a v a 2 s . com } Cursor c = new SmsDataProvider(_context).query(mbURI, "date > ?", new String[] { sinceDate.toString() }); // Reading mailbox if (c != null && c.getCount() > 0) { c.moveToFirst(); do { JSONObject entry = new JSONObject(); try { for (int idx = 0; idx < c.getColumnCount(); idx++) { String colName = c.getColumnName(idx); // Id column is must be an integer if (colName.equals(new String("_id")) || colName.equals(new String("type"))) { entry.put(colName, c.getInt(idx)); // bufferize Id for future use if (colName.equals(new String("_id"))) { } } // Seen and read must be pseudo boolean else if (colName.equals(new String("read")) || colName.equals(new String("seen"))) { entry.put(colName, c.getInt(idx) > 0 ? "true" : "false"); } else { // Special case for date, we need to record last without searching if (colName.equals(new String("date"))) { final Long tmpDate = c.getLong(idx); if (tmpDate > _lastMsgDate) { _lastMsgDate = tmpDate; } } entry.put(colName, c.getString(idx)); } } // Mailbox ID is required by server entry.put("mbox", mbID.ordinal()); _jsonDataDump.put(entry); } catch (JSONException e) { Log.e(TAG, "JSON Exception when reading SMS Mailbox", e); c.close(); } } while (c.moveToNext()); Log.d(TAG, c.getCount() + " messages read from " + mbURI); c.close(); } }
From source file:com.guess.license.plate.Task.LoadingTaskConn.java
private void setDefaultValues() { if (databaseHelper != null) { db = databaseHelper.getReadableDatabase(); Cursor cursor = db.query("Plate", null, null, null, null, null, null); int count = cursor.getCount(); if (count == 0) { // Setting all the default setting values SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sharedPref.edit(); editor.putString(Preferences.LANGUAGE.toString(), Locale.getDefault().getLanguage()); editor.putString(Preferences.THEME.toString(), "Theme 1"); editor.putString(Preferences.RANGE.toString(), "Europe"); editor.putBoolean(Preferences.UPDATE.toString(), true); editor.putBoolean(Preferences.SOUND.toString(), false); editor.commit();/* w ww . j a v a 2 s. c om*/ // Insert Build InitialData.InsertBuild(db); // Insert Plate InitialData.InsertPlate(db); // Insert Language InitialData.InsertLang(db); } db.close(); } }
From source file:com.ubikod.urbantag.model.TagManager.java
/** * Get all tags from a pivot table//from w ww.j a v a 2s.co m * @param pivotTable pivot table name * @param pivotColumn pivot table column * @param id * @return */ private List<Tag> dbGetAllFor(String pivotTable, String pivotColumn, int id) { open(); String query = "SELECT " + DatabaseHelper.TAG_COL_ID + ", " + DatabaseHelper.TAG_COL_NAME + ", " + DatabaseHelper.TAG_COL_COLOR + ", " + DatabaseHelper.TAG_COL_NOTIFY + " FROM " + DatabaseHelper.TABLE_TAGS + " tags INNER JOIN " + pivotTable + " pivot ON tags." + DatabaseHelper.TAG_COL_ID + "=pivot." + DatabaseHelper.CONTENT_TAG_COL_TAG + " WHERE pivot." + pivotColumn + "=?"; Cursor c = mDB.rawQuery(query, new String[] { String.valueOf(id) }); List<Tag> tags = new ArrayList<Tag>(); if (c.getCount() == 0) { c.close(); close(); return tags; } c.moveToFirst(); do { Tag t = cursorToTag(c); tags.add(t); } while (c.moveToNext()); c.close(); close(); return tags; }
From source file:fr.mixit.android.ui.StarredActivity.java
/** {@inheritDoc} */ public void onQueryComplete(int token, Object cookie, Cursor cursor) { try {//from w ww.j ava2 s .co m if (!cursor.moveToFirst()) return; starredSessionCount = cursor.getCount(); onTabChange(getTabHost().getCurrentTabTag()); } finally { cursor.close(); } }
From source file:com.HskPackage.HskNamespace.HSK1ProjectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//w w w . jav a 2 s . c o m final TextView codice = (TextView) findViewById(R.id.codice); final Button carattere = (Button) findViewById(R.id.carattere); final TextView fonetica = (TextView) findViewById(R.id.fonetica); final TextView significato = (TextView) findViewById(R.id.significato); /*********** CREATE A DATABASE ******************************************************/ final String DB_PATH = "/data/data/com.HskPackage.HskNamespace/"; final String DB_NAME = "chineseX.db"; SQLiteDatabase db = null; boolean exists = (new File(DB_PATH + DB_NAME)).exists(); AssetManager assetManager = getAssets(); if (!exists) { try { InputStream in = assetManager.open(DB_NAME); OutputStream out = new FileOutputStream(DB_PATH + DB_NAME); copyFile(in, out); in.close(); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } File dbFile = new File(DB_PATH + DB_NAME); db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); } else { File dbFile = new File(DB_PATH + DB_NAME); db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); } final Integer valore = 1; //String query = "SELECT * FROM chineseX"; String query = "SELECT * FROM chineseX where _id = ? "; String[] selectionArgs = { valore.toString() }; Cursor cursor = null; cursor = db.rawQuery(query, selectionArgs); //cursor = db.rawQuery(query, null); int count = cursor.getCount(); System.out.println("il numero di dati contenuti nel database " + count); while (cursor.moveToNext()) { long id = cursor.getLong(0); System.out.println("Questo l'ID ====>" + id); scodice = cursor.getString(1); codice.setText(scodice); System.out.println("Questo il codice ====>" + codice); scarattere = cursor.getString(2); carattere.setText(scarattere); System.out.println("Questo il carattere ====>" + carattere); sfonetica = cursor.getString(3); fonetica.setText(sfonetica); System.out.println("Questo il fonet ====>" + fonetica); ssignificato = cursor.getString(4); significato.setText("?? - Visualizza Significato"); System.out.println("Questo il carattere ====>" + ssignificato); } //fine db.close(); //set up sound button final MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.hangout_ringtone); //final MediaPlayer chword001 = MediaPlayer.create(this, R.raw.ayi001); /* // set up change Images miaImmagine = (ImageView) findViewById(R.id.Image); // dichiaro l'oggetto image view miaImmagine.setImageResource(R.drawable.uno1); // associo l'immagine alla figura uno // setto un evento di cattura del click sull'immagine miaImmagine.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { //chword001.start(); } }) ; */ final Intent first = new Intent(this, Activity2.class); final Intent immagine = new Intent(this, Activity3.class); /* * Un intent definito nella javadoc della classe android.content.Intent come una * "descrizione astratta dell'operazione da eseguire". * E un intent ESPLICITO perch cosciamo il destinatario. * Passiamo come parametri il context attuale ed la classe che identifica l'activity di destinazione. * E' importante che la classe sia registrata nell'AndroidManifest.xml * */ Button b = (Button) this.findViewById(R.id.button1); Button b2 = (Button) this.findViewById(R.id.button2); Button b3 = (Button) this.findViewById(R.id.carattere); b.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 1; valore = valore + 1; if (valore >= 153) { valore = 1; } System.out.println("AVANTI" + valore); first.putExtra("AVANTI", valore); startActivity(first); finish(); mpButtonClick.start(); } }); b2.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 153; System.out.println("AVANTI == >" + valore); first.putExtra("AVANTI", valore); startActivity(first); finish(); mpButtonClick.start(); } }); b3.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 1; System.out.println("AVANTI" + valore); immagine.putExtra("AVANTI", valore); startActivity(immagine); finish(); mpButtonClick.start(); } }); }
From source file:eu.e43.impeller.uikit.ActivityAdapter.java
public void updateCursor(Cursor c) { if (m_cursor != null && m_cursor != c) m_cursor.close();// ww w .j a v a2s .co m m_cursor = c; m_lastScannedObjectPosition = 0; m_objectPositions.clear(); if (m_cursor != null) Log.v(TAG, "Updated with " + c.getCount() + " activities"); notifyDataSetChanged(); }