Mobile Security defender Learning 3--blacklist interception

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.