how to compare values with database values

前端 未结 1 936
不知归路
不知归路 2021-01-29 09:34

im insertinguser installed app package name in database using below code and is insert sucessfully show me in log now i want to compare system install apped with this database v

相关标签:
1条回答
  • 2021-01-29 10:12

    to get list from database

    add this method in your Database Handler

    public ArrayList<String> getAllApps() {
    
        String selectQuery = "SELECT  * FROM table";
         ArrayList<String> apps = new ArrayList<String>();
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);
    
        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                apps.add(cursor.getString("your column name"));
            } while (cursor.moveToNext());
        }
    
        // return list
        return apps;
    }
    

    first Get the list from the database and add to the Arraylist
    then compare your app name with them

    arraylist = dbHelper.getAllApps();
    

    in your if ( ((p.packageName).equals("db.list???"))
    replace with

     if (arraylist.contains(p.packageName))
        {
           add();
        }
        else
        {
         donothing();
        }
    
    0 讨论(0)
提交回复
热议问题