1 Create a helper class for a database and override its construction method
Packagecom.djf.mobilesafty.blacknumber.db;ImportAndroid.content.Context;Importandroid.database.sqlite.SQLiteDatabase;Importandroid.database.sqlite.SQLiteDatabase.CursorFactory;ImportAndroid.database.sqlite.SQLiteOpenHelper;ImportAndroid.nfc.NfcAdapter.CreateBeamUrisCallback; Public classBlacknumberopendbhelperextendsSqliteopenhelper { PublicBlacknumberopendbhelper (Context context, String name, Cursorfactory factory,intversion) { Super(Context, "blacknumber.db",NULL, 1); //TODO auto-generated Constructor stub} @Override Public voidonCreate (Sqlitedatabase db) {//TODO auto-generated Method StubDb.execsql ("CREATE Table Blacknumber (_id integer PRIMARY key autoincrement, number Verchar (), Mode Verchar (2))"); } @Override Public voidOnupgrade (Sqlitedatabase db,intOldversion,intnewversion) { //TODO auto-generated Method Stub }}
2 the method of adding additions and deletions to database creation
PackageCom.djf.mobilesafty.blacknumber.dao;Importjava.util.ArrayList;Importjava.util.List;Importandroid.content.ContentValues;ImportAndroid.content.Context;ImportAndroid.database.Cursor;Importandroid.database.sqlite.SQLiteDatabase;ImportCom.djf.mobilesafty.blacknumber.db.BlackNumberOpenDBhelper;ImportCom.djf.mobilesafty.blacknumber.domin.NumberInfo; Public classBlacknumberdao {PrivateBlacknumberopendbhelper Helper; /*** Construction Method*/ PublicBlacknumberdao (Context context) {Helper=NewBlacknumberopendbhelper (Context, "blacknumber.db",NULL, 1); } /*** * Check if blacklist exists*/ Public BooleanFindnumber (String number) {Booleanresult =false; Sqlitedatabase DB=helper.getreadabledatabase (); Cursor Cursor=Db.rawquery ("SELECT * from Blacknumber where number=?", Newstring[] {number}); if(Cursor.movetonext ()) {result=true; } cursor.close (); Db.close (); returnresult; } /*** * Check all blacklists*/ PublicList<numberinfo>FindAll () {List<NumberInfo> info =NewArraylist<numberinfo>(); Sqlitedatabase DB=helper.getreadabledatabase (); Cursor Cursor=db.rawquery ("Select number, mode from Blacknumber",NULL); while(Cursor.movetonext ()) {Numberinfo Numberinfo=NewNumberinfo (); String Number= cursor.getstring (0); String Mode= cursor.getstring (1); Numberinfo.setnumber (number); Numberinfo.setmode (mode); Info.add (Numberinfo); } cursor.close (); Db.close (); returninfo; } /*** Add blacklist * Mode 1 SMS Intercept 2 call intercept 3 all intercept*/ Public voidAdd (string number, String mode) {Sqlitedatabase db=helper.getwritabledatabase (); Contentvalues CV=Newcontentvalues (); Cv.put ("Number", number); Cv.put ("Mode", mode); Db.insert ("Blacknumber",NULL, CV); Db.close (); } /*** Add blacklist * Modify intercept mode*/ Public voidUpdate (string number, String mode) {Sqlitedatabase db=helper.getwritabledatabase (); Contentvalues CV=Newcontentvalues (); Cv.put ("Mode", mode); Db.update ("Blacknumber", CV, "number=?",NewString[]{number}); Db.close (); } /*** Delete blacklist * Modify intercept mode*/ Public voidDelete (String number) {Sqlitedatabase db=helper.getwritabledatabase (); Db.delete ("Blacknumber", "number=?",NewString[]{number}); Db.close (); }}
3 Business class to create related information
Packagecom.djf.mobilesafty.blacknumber.domin; Public classNumberinfo {PrivateString number;PrivateString mode; PublicString GetNumber () {returnNumber ;} Public voidSetnumber (String number) { This. Number =Number ;} PublicString GetMode () {returnmode;} Public voidSetMode (String mode) { This. Mode =mode;} @Override PublicString toString () {return"Numberinfor [number=" + number + ", mode=" + mode + "]";}}
Mobile Security defender Learning 3--blacklist interception