归属地查询代码
发布日期:2021-06-29 15:21:45
浏览次数:2
分类:技术文章
本文共 5827 字,大约阅读时间需要 19 分钟。
http://download.csdn.net/detail/a332324956/6927141
主要代码片段为:
package com.lxm.app;import android.app.Activity;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.os.Bundle;import android.os.Handler;import android.os.Looper;import android.os.Message;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.Toast;import cn.waps.AppConnect;public class CallerlocationActivity extends Activity implements OnClickListener { /** Called when the activity is first created. */ private Button Inquire; private Button Save; private EditText InputNum; private TextView ShowNum; private TextView ShowCallerLocation; private String datapath; private static String dbname = "callerlocation.db"; private Handler subHandler; public final static int INQUIRE_ENUM = 0; public final static int SAVE_ENUM = 1; public final static int INQUIRE_STATUS_DOING = 0; public final static int INQUIRE_STATUS_END = 1; public final static int INQUIRE_STATUS_CALLERNUM = 2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Inquire = (Button) findViewById(R.id.button1); Save = (Button) findViewById(R.id.button2); Inquire.setOnClickListener(this); Save.setOnClickListener(this); ShowNum = (TextView) findViewById(R.id.textView3); ShowCallerLocation = (TextView) findViewById(R.id.textView4); InputNum = (EditText) findViewById(R.id.editText1); datapath = "/data/data/" + this.getPackageName().toString() + "/databases"; AppConnect.getInstance(this); AppConnect.getInstance(this).initPopAd(this); AppConnect.getInstance(this).showPopAd(this); LinearLayout adlayout =(LinearLayout)findViewById(R.id.AdLinearLayout); AppConnect.getInstance(this).showBannerAd(this, adlayout); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); AppConnect.getInstance(this).close(); } private Handler handler = new Handler() { String Location; public void handleMessage(android.os.Message msg) { switch (msg.what) { case INQUIRE_STATUS_END: Inquire.setEnabled(true); break; case INQUIRE_STATUS_DOING: Message Sendmsg = Message.obtain(); Sendmsg.what = INQUIRE_ENUM; Sendmsg.obj = new String(InputNum.getText().toString()); subHandler.sendMessage(Sendmsg); Inquire.setEnabled(false); break; case INQUIRE_STATUS_CALLERNUM: Location = (String) msg.obj; ShowNum.setText(InputNum.getText().toString()); ShowCallerLocation.setText(Location); break; default: break; } } }; @Override public void onClick(View v) { if (v.equals(Inquire)) { ShowNum.setText(""); ShowCallerLocation.setText(""); if (InputNum.length() == 0) { Toast.makeText(this, "请输入号码!", Toast.LENGTH_LONG).show(); return; } if (InputNum.length() < 3) { Toast.makeText(this, "请修改输入!", Toast.LENGTH_LONG).show(); return; } new Thread() { public void run() { Looper.prepare(); handler.sendEmptyMessage(INQUIRE_STATUS_DOING); subHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case INQUIRE_ENUM: String InquireNum = (String) msg.obj; try { // 首先将数据复制出去到data区域 String callerName = ""; CopyRawtodata.CopyRawtodata(datapath, dbname, getApplicationContext(), R.raw.callerlocation, true); // // Thread.sleep(1000); callerName = InquireCallerPos(InquireNum, datapath, dbname); Message Sendmsg = Message.obtain(); Sendmsg.what = 2; Sendmsg.obj = new String(callerName); handler.sendMessage(Sendmsg); } catch (Exception e) { e.printStackTrace(); subHandler.getLooper().quit(); } finally { handler.sendEmptyMessage(INQUIRE_STATUS_END); subHandler.getLooper().quit(); } break; case SAVE_ENUM: break; default: break; }// end switch } }; Looper.loop(); } }.start(); } else if (v.equals(Save)) { } } // 查询数据,依据号码,返回归属地位置,数据库查询接口当前未作封装,直接处理 private String InquireCallerPos(String num, String dbpath, String dbname) { int cityId = 0; String callerName = "未知属地"; SQLiteDatabase db = openOrCreateDatabase(dbpath + "/" + dbname, Context.MODE_PRIVATE, null); Cursor cursor = null; boolean IsNeed2Search = false; if (num.length() < 7) { Log.i("lxm", num); cursor = db.rawQuery("select * from phones WHERE number = " + num, null); } else { IsNeed2Search = true; String tmp = num.substring(0, 7); Log.i("lxm", "" + tmp); cursor = db.rawQuery("select * from mobiles WHERE number = " + tmp, null); } if (IsNeed2Search) { if (0 == cursor.getCount()) { String tmp = num.substring(0, 3); cursor = db.rawQuery("select * from phones WHERE number = " + tmp, null); } if (0 == cursor.getCount()) { String tmp = num.substring(0, 4); cursor = db.rawQuery("select * from phones WHERE number = " + tmp, null); } if (0 == cursor.getCount()) { String tmp = num.substring(0, 5); cursor = db.rawQuery("select * from phones WHERE number = " + tmp, null); } } if (0 == cursor.getCount()) { Log.i("lxm", "" + "xxxxx"); } while (cursor.moveToNext()) { cityId = cursor.getInt(cursor.getColumnIndex("cityid")); } cursor = db .rawQuery("select * from cities WHERE _id = " + cityId, null); while (cursor.moveToNext()) { callerName = cursor.getString(cursor.getColumnIndex("name")); } db.close(); Log.i("lxm", "" + cityId + " " + callerName); return callerName; }}
代码比较简单,大家可以自己阅读查看了。
转载地址:https://codegg.blog.csdn.net/article/details/19291933 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
很好
[***.229.124.182]2024年04月11日 10时57分19秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
java 使用GDAL生产tif格式
2019-04-29
Node,js 事件循环原理(Event loop)
2019-04-29
CSS3&JavaScript 图片分隔切换
2019-04-29
CSS3&JavaScript 瀑布流
2019-04-29
tomcat配置JVM
2019-04-29
Oracle获取连接超级慢的问题
2019-04-29
关于HashMap初始化容量,设置多少合适。
2019-04-29
MYSQL 自定义函数
2019-04-29
早鸟票倒计时3天 | 2019携程技术峰会,11月9日上海(含福利)
2019-04-29
干货 | 微信小程序一键转百度小程序,携程火车票团队是这样做的
2019-04-29
沙龙回顾 | 移动互联网下的测试工程效率提升,含PPT和视频
2019-04-29
程里人 | 携程程序猿/媛的1024
2019-04-29
常见的字符集编码
2019-04-29
前端(一):字符与语义标签
2019-04-29
前端(二):CSS语法与选择器
2019-04-29
前端(三):样式继承与其他概念
2019-04-29
前端(四):样式继承与其他概念
2019-04-29
前端小案例:田径场
2019-04-29
前端(五):浮动
2019-04-29
前端(六):高度塌陷与BFC
2019-04-29