求手机号码归属地sqlite数据库

nainai007 2011-09-06 09:11:01
如题,有的话,可否发一份给小弟

或者手机号码的编码规律

或者查询在线api接口,之前用一个在线的api接口,现在不能用了
...全文
869 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mayiming23 2013-07-25
  • 打赏
  • 举报
回复
求带本地数据库的源码!急用!谁有的话给我一份!!397910207@qq.com
alanz1982 2012-06-13
  • 打赏
  • 举报
回复
求数据库啊~~~366914542@qq.com
lizhengjun2010 2011-09-24
  • 打赏
  • 举报
回复
查询手机号码归属地:
http://www.yodao.com/smartresult-xml/search.s?type=mobile&q=手机号

有道在线接口!解析xml数据就行
yl592478186 2011-09-24
  • 打赏
  • 举报
回复
手机号归属地的数据库可以共享一下吗?
cs08dn201109 2011-09-08
  • 打赏
  • 举报
回复
旺旺fisherword有,www.i-onservice.com
nainai007 2011-09-08
  • 打赏
  • 举报
回复
lovestevevai 可否发给我一下,谢谢了
标哥 2011-09-07
  • 打赏
  • 举报
回复
以下是我之前写的代码,楼主参考下
访问了本地的手机归属地信息的数据库,楼主需要的话我可以发给你

package com.litian.mobilesafe.service;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.litian.mobilesafe.R;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
* 手机号 是11位的.
* 固定电话 本地号码7位 ,8位
* 长途号码 带区号 区号有3位和4位的
* 10位 3位区号+7位电话号码
* 11位 4位区号+7位电话 3位区号+8位电话
* 12位 4位区号+8位电话
*/

/**
* 提供来电区域查询的服务
* @author Administrator
*/
public class AddressService {

private static final String TAG = "AddressService";
private static final String DB_NAME = "address.db";

private Context context;

public AddressService(Context context){
this.context = context;
}

/**
* 判断数据库是否存在
* @return
*/
public boolean isExist(){
//this.context.getFilesDir()表手机文件目录
File file = new File(this.context.getFilesDir(), DB_NAME);
return file.exists();
}

/**
* 拷贝数据库到系统的<包名>/data/data/下
* @throws IOException
*/
public void copyDbToFileDir(){
InputStream in = null;
FileOutputStream fos = null;

try {
in = this.getClass().getClassLoader().getResourceAsStream("address.db");
File file = new File(context.getFilesDir(), DB_NAME);

fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
//int len = 0;
int len = -1;

while((len = in.read(buffer)) != -1){
//while((len = in.read()) > 0){
fos.write(buffer, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

/**
* 查询指定号码的所属区域
* @param number
* @return
*/
public String getAddress(String number){
Log.i(TAG, "fuck you getAddress!");
File file = new File(context.getFilesDir(), DB_NAME);
String address = number; //地址初始值赋为电话号码

//打开数据库
//openDatabase(path, factory, flags)
SQLiteDatabase db = SQLiteDatabase.openDatabase(
file.getAbsolutePath(),
null,
SQLiteDatabase.OPEN_READONLY);

if(db.isOpen()){
//判断手机号的正则表达式:^1[358]\\d{9}$
Pattern pattern = Pattern.compile("^1[358]\\d{9}$");
Matcher matcher = pattern.matcher(number);
boolean isMatched = matcher.matches();
if(isMatched){
//如果匹配手机号,则取前7位(判断区域用)
String phonePref7 = number.substring(0, 7);
Log.i(TAG, "手机号的前7位为:" + phonePref7);

//查询数据库中的city字段,跟手机号码的前7位对比
Cursor cursor = db.rawQuery(
"select city from info where mobileprefix=?",
new String[]{phonePref7});

if(cursor.moveToFirst()){
address = cursor.getString(0);
}
cursor.close();
}else{
//否则是座机
Cursor cursor = null;
/**
* 手机号 是11位的.
* 固定电话 本地号码7位 ,8位
* 长途号码 带区号 区号有3位和4位的
* 10位 3位区号+7位电话号码
* 11位 4位区号+7位电话 3位区号+8位电话
* 12位 4位区号+8位电话
*/

//根据座机区号的不同长度来判断区域位置
switch (number.length()) {
case 7:
case 8:
//电话号码为7位或8位的都是本地号码
address = context.getApplicationContext().getResources().getString(R.string.local_number);
break;

case 10:
//号码长度为10则区号长度为3
String numberPref3 = number.substring(0, 3);

cursor = db.rawQuery(
"select city from info where area=?",
new String[]{numberPref3});

if(cursor.moveToFirst()){
address = cursor.getString(0);
}
cursor.close();
break;

case 11:
//号码长度为11则区号长度为3或4
String numberPref_3 = number.substring(0, 3);
String numberPref_4 = number.substring(0, 4);

cursor = db.rawQuery(
"select city from info where area=? or area=?",
new String[]{numberPref_3, numberPref_4});

if(cursor.moveToFirst()){
address = cursor.getString(0);
}
cursor.close();
break;

case 12:
//号码长度为10则区号长度为3
String numberPref4 = number.substring(0, 4);
cursor = db.rawQuery(
"select city from info where area=?",
new String[]{numberPref4});
if(cursor.moveToFirst()){
address = cursor.getString(0);
}
cursor.close();
break;

case 4:
//电话号码为4位,则表示android模拟器自身
address = context.getApplicationContext().getResources().getString(R.string.emulator_number);
break;

default:
break;
}
}//end of big "else"
Log.i(TAG, "comingNumber is: " + number);
Log.i(TAG, "Arddess is: " + address);
db.close();
}

//return address;
return address + "by~~标哥";
}
}

80,356

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧