Thursday, July 2, 2015

Retrieve data from Sqlite in android

You can use this to retrieve data from Sqlite.
First use this code where you need retrieved data :
 OurAppsPackages = new ArrayList<String>();
        OurAppsPackages = databaseHelper.getOurAllAppsPackage();
Use bellow code in B2MDatabaseHelper class where your database.
 public ArrayList<String> getOurAllAppsPackage() {
        SQLiteDatabase db = this.getWritableDatabase();
        // Cursor cursor = db.query("day_info", null, " emp_name=?", new String[]{userName}, null, null, null);
        Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null);
        cursor.moveToFirst();
        ArrayList<String> pkgs= new ArrayList<String>();

        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            for (int i = 0; i < cursor.getCount(); i++) {
                String pkgN = cursor.getString(cursor.getColumnIndex("PackageName"));
                pkgs.add(pkgN.toString());
                cursor.moveToNext();
            }
        }
        return pkgs;
    }

No comments:

Post a Comment