An analysis of the number attribution of Android phone defender _android

Source: Internet
Author: User
Tags md5 encryption create database

Using the Millet number attribution database, there are two tables Data1 and DATA2

First inquires the Data1 table, the cell phone number intercepts the first 7 digits

Select Outkey from data1 where id= "top seven cell phone numbers"

And then query the Data2 table,

Select location from data2 where id= "Outkey detected above"

You can use subqueries

Select location from data2 where id= (select Outkey from data1 where id= "Top 7 cell phone Numbers")

Create DATABASE Tools Class

Create a new package Xxx.db.dao

Create a new class Numberaddressutils, create a new static method Querynumber

Call the Sqlitedatabase.opendatabase () method to get to the Sqlitedatabase object, Parameter: Database path (/data/data/package name/files/ XXX.DB), cursor factory (NULL), open mode (sqlitedatabse.open_readonly)

Copy the database address.db to the/data/data/package name/files/Directory

Invokes the Rawquery () method of the Sqlitedatabase object, gets to the cursor object, queries the data, parameters: SQL statements, string[] An array of conditions

For example: Select location from Data2 where id= (select Outkey from Data1 where id=?), New String[]{phone.substring (0,7)}

While loops cursor objects, conditions call the MoveToNext () method of the Cursor object

Loop to call the cursor object's GetString () method, passing in the field index

Closes the close () method of the cursor cursor object

Get the address back.

Copy database from assets directory to data directory

On the Welcome page, make a copy

Call the Getassets (). Open () method to get the InputStream object, parameter: Xxx.db file name

Get the file object, new out, Parameters: Getfilesdir () gets to the/data/data/package/files/directory, xxx.db

Get FileOutputStream object, new out, Parameter: file object

Define buffer byte[] buffer, general 1024

Definition length Len

While loop read, condition: Read in length is not 1

The write () method of the FileOutputStream object is called in the loop, parameter: buffer, starting at 0, Len length

Call the Close () method of the InputStream object

The exist () method and the length () method for calling the file object are larger than 0, as long as the presence and length are longer than 0.

Numberqueryaddressutil.java

Package com.qingguow.mobilesafe.utils;
Import Android.database.Cursor;
Import Android.database.sqlite.SQLiteDatabase;
public class Numberqueryaddressutil {
private static final String path = '/data/data/com.qingguow.mobilesafe/files/ Address.db ";
/**
*
@param phone
* @return
/public
static string queryaddress (String phone) {
Sqlitedatabase db=sqlitedatabase.opendatabase (path, null,sqlitedatabase.open_readonly);
Cursor cursor=db.rawquery ("Select location from Data2 where id= (select Outkey from Data1 where id=?)", New String[]{phone. SUBSTRING (0,7)});
while (Cursor.movetonext ()) {
String address=cursor.getstring (0);
return address;
Cursor.close ();
Return "";
}

Copy Database

private void Copyaddressdatabase () {
try {
///To determine whether there is
a file File = new file (Getfilesdir (), "address.db");
if (file.exists () && file.length () > 0) {return
;
}
InputStream is = Getassets (). Open ("address.db");
FileOutputStream fos = new FileOutputStream (file);
byte[] buffer = new byte[1024];
int len = 0;
while (len = is.read (buffer))!=-1) {
fos.write (buffer, 0, Len);
}
Is.close ();
Fos.close ();
} catch (Exception e) {
e.printstacktrace ();
}
}

Recommended reading:

An analysis of Android phone defender SIM card binding

An in-depth analysis of the Android phone defender MD5 encryption when saving passwords

Detailed Android Phone Guardian Settings Wizard page

An analysis of Android phone defender turn off automatic Updates

A brief analysis of Android phone defender custom control properties

An analysis of Android phone defender reading contacts

On the Android handset Guardian receives the short message instruction to carry on the corresponding operation

On the principle of mobile phone positioning of Android mobile phone Guardian

On the mobile phone of Android mobile phone to realize the location of SMS command acquisition

The above content is small series to introduce the Android phone number of the guardian of the relevant content inquiries, I hope to help you!

Related Article

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.