/**
* 号码归属地查询的 dao
*
@author
Administrator
*
*/
public
class
AddressDao {
public
static
String getAddress(String number,Context context){
String location=
null
;
//打开数据库
SQLiteDatabase db=SQLiteDatabase.openDatabase(
"/data/data/"
+context.getPackageName()+
"/files/address.db"
,
null
,SQLiteDatabase.
OPEN_READONLY
);
//判断传入的号码是否是手机号
if
(number.matches(
"^1[3458]\\d{9}$"
)) {
// 手机号码
Cursor cursor = db.rawQuery(
"select location from data2 where id=(select outkey from data1 where id=?)"
,
new
String[]{number.substring(0, 7)});
if
(cursor.moveToFirst()){
location=cursor.getString(0);
}
cursor.close();
db.close();
//关闭数据库
}
else
{
Toast. makeText(context,
"输入的手机号有误"
, 0).show();
}
return
location;
}
}