package com.pixtas.smsfilter.service;
import java.util.ArrayList;
import java.util.List;
import com.pixtas.helper.DatabaseAdapterHelper;
import com.pixtas.smsfilter.Config;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.media.AudioManager;
import android.os.Bundle;
import android.provider.Contacts;
import android.telephony.PhoneStateListener;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.SlidingDrawer;
public class SmsReceiver extends BroadcastReceiver{
private static final String TAG = "SmsReceiver";
// private List<String> nameContactsInPhone = new ArrayList<String>();
private List<String> numberContactsInPhone = new ArrayList<String>();
private Context mContext = null;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
this.mContext = context;
String incomingNumber = null;
if(intent.getAction().equals(Config.SMS_RECEIVE_ACTION)) {
getContactsInfoListFromPhone(context);
if(isReceive(context)){
Bundle bundle = intent.getExtras();
Object[] myOBJdups = (Object[]) bundle.get("pdus");
SmsMessage[] smsMessages = new SmsMessage[myOBJdups.length];
for(int i= 0;i < myOBJdups.length; i ++){
smsMessages[i] = SmsMessage.createFromPdu((byte[]) myOBJdups[i]);
incomingNumber = smsMessages[i].getDisplayOriginatingAddress();
}
if(Config.debug){
Log.v(TAG,"sms---->incomingNumber:" + incomingNumber);
}
boolean isExist = isExist(incomingNumber);
if(!isExist){
if(Config.debug){
Log.v(TAG,incomingNumber + "-sms------>is not in contacts,change silent");
}
this.changeSilent();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(2000);
if(Config.debug){
Log.v(TAG,"----sms---->change normal");
}
changeNormal();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}else{
if(Config.debug){
Log.v(TAG,incomingNumber + "-sms------>change nomal");
}
this.changeNormal();
}
}
}else if(intent.getAction().equals(Config.PHONE_STATE)){
getContactsInfoListFromPhone(context);
if(isReceive(context)){
Bundle bundle = intent.getExtras();
incomingNumber = bundle.getString("incoming_number");
if(Config.debug){
Log.v(TAG,"ring--->incomingNumber:" + incomingNumber);
}
mPhoneCallListener phoneListener = new mPhoneCallListener();
TelephonyManager telMgr = (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE);
telMgr.listen(phoneListener, mPhoneCallListener.LISTEN_CALL_STATE);
}
}
}
/*来电监听器*/
private class mPhoneCallListener extends PhoneStateListener
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
// TODO Auto-generated method stub
switch(state)
{
/*无任何状态*/
case TelephonyManager.CALL_STATE_IDLE:
if(Config.debug){
Log.v(TAG,"CALL_STATE_IDLE change nomal");
}
changeNormal();
break;
/*接起电话的状态*/
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
/*来电状态*/
case TelephonyManager.CALL_STATE_RINGING:
/*当来电号码不在联系人*/
boolean isExist = isExist(incomingNumber);
if(!isExist && isReceive(mContext))
{
if(Config.debug){
Log.v(TAG,incomingNumber + "-->is not in contacts,change silent");
}
changeSilent();
}
}
super.onCallStateChanged(state, incomingNumber);
}
}
private boolean isExist(String incomingNumber){
for(int i = 0; i < numberContactsInPhone.size(); i ++){
String numberContact = numberContactsInPhone.get(i).replace("-", "");
if(Config.debug){
Log.v(TAG, "numberContact-->" + numberContact);
}
int NCLen = numberContact.length();
int INLen = incomingNumber.length();
if(NCLen <= INLen){
String temp = incomingNumber.substring(incomingNumber.length() - numberContact.length(), incomingNumber.length());
if(numberContact.equals(temp)){
return true;
}
}
}
return false;
}
private boolean isReceive(Context context){
DatabaseAdapterHelper databaseAdapterHelper = new DatabaseAdapterHelper(context);
databaseAdapterHelper.open_sms();
Cursor cursor = databaseAdapterHelper.fetchAllData();
if(cursor.getCount() > 0){
cursor.moveToFirst();
int flag = cursor.getInt(cursor.getColumnIndex("data"));
if(flag == 1){
return true;
}
}
cursor.close();
databaseAdapterHelper.close_sms();
return false;
}
private void getContactsInfoListFromPhone(Context context) {
/* 取得ContentResolver */
ContentResolver content = context.getContentResolver();
/* 取得通讯录的Phones表的cursor */
Cursor contactcursor = content.query(Contacts.Phones.CONTENT_URI, null,
null, null, Contacts.People.DEFAULT_SORT_ORDER);
/* 在LogCat里打印所有关于的列名 */
// for (int i = 0; i < contactcursor.getColumnCount(); i++) {
// String columnName = contactcursor.getColumnName(i);
// Log.d(TAG, "column name:" + columnName);
// }
/* 逐条读取记录信息 */
int Num = contactcursor.getCount();
String number;
for (int i = 0; i < Num; i++) {
contactcursor.moveToPosition(i);
// String type = contactcursor.getString(contactcursor.getColumnIndexOrThrow(Contacts.Phones.TYPE));
// Log.v(TAG, "type=" + type);
// String person_id = contactcursor.getString(contactcursor
// .getColumnIndexOrThrow(Contacts.Phones.PERSON_ID));
// Log.v(TAG, "person_id=" + person_id);
// name = contactcursor.getString(contactcursor
// .getColumnIndexOrThrow(Contacts.Phones.NAME));
number = contactcursor.getString(contactcursor
.getColumnIndexOrThrow(Contacts.Phones.NUMBER));
// number = number == null ? "无输入电话" : number;// 当找不到电话时显示"无输入电话"
// nameContactsInPhone.add(name);
// Log.v(TAG, "name=" + name);
numberContactsInPhone.add(number);
if(Config.debug){
// Log.v(TAG, "*****number=" + number);
}
}
}
/*手机静音*/
private void changeSilent(){
try
{
AudioManager audioManager = (AudioManager)
mContext.getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null)
{
/*设置静音*/
audioManager.setRingerMode(AudioManager.
RINGER_MODE_SILENT);
audioManager.getStreamVolume(
AudioManager.STREAM_RING);
}
}catch(Exception e)
{
e.printStackTrace();
}
}
/*手机铃声正常*/
private void changeNormal(){
try
{
AudioManager audioManager = (AudioManager)
mContext.getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null)
{
/*设置铃声正常*/
audioManager.setRingerMode(AudioManager.
RINGER_MODE_NORMAL);
audioManager.getStreamVolume(
AudioManager.STREAM_RING);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
小程序 信息过滤功能源码.rar
共90个文件
svn-base:25个
entries:22个
class:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 60 浏览量
2023-02-03
11:52:29
上传
评论
收藏 211KB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序 信息过滤功能源码.rar (90个子文件)
1_121116141641_1.png 43KB
Android 信息过滤功能源码
lib
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 194B
.classpath 280B
assets
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 197B
src
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 204B
com
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 211B
pixtas
helper
DatabaseAdapterHelper.java 3KB
DialogHelper.java 480B
.svn
prop-base
text-base
DatabaseAdapterHelper.java.svn-base 3KB
DialogHelper.java.svn-base 480B
props
tmp
prop-base
text-base
props
entries 528B
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 234B
smsfilter
Config.java 1KB
rest
.svn
prop-base
text-base
RestAPI.java.svn-base 2KB
props
tmp
prop-base
text-base
props
entries 369B
RestAPI.java 2KB
activity
.svn
prop-base
text-base
Main.java.svn-base 6KB
props
tmp
prop-base
text-base
props
entries 370B
Main.java 6KB
service
SmsReceiver.java 8KB
.svn
prop-base
text-base
SmsReceiver.java.svn-base 8KB
props
tmp
prop-base
text-base
props
entries 376B
.svn
prop-base
text-base
Config.java.svn-base 1KB
props
tmp
prop-base
text-base
props
entries 403B
res
drawable-mdpi
.svn
prop-base
icon.png.svn-base 53B
text-base
icon.png.svn-base 5KB
props
tmp
prop-base
text-base
props
entries 362B
icon.png 5KB
drawable-ldpi
.svn
prop-base
icon.png.svn-base 53B
text-base
icon.png.svn-base 5KB
props
tmp
prop-base
text-base
props
entries 362B
icon.png 5KB
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 280B
values
.svn
prop-base
text-base
strings.xml.svn-base 1KB
color.xml.svn-base 137B
props
tmp
prop-base
text-base
props
entries 494B
strings.xml 1KB
color.xml 137B
layout
main.xml 2KB
.svn
prop-base
text-base
main.xml.svn-base 2KB
props
tmp
prop-base
text-base
props
entries 346B
drawable-hdpi
ic_menu_block.png 4KB
.svn
prop-base
ic_menu_block.png.svn-base 53B
icon.png.svn-base 53B
ic_menu_about.png.svn-base 53B
text-base
ic_menu_block.png.svn-base 4KB
icon.png.svn-base 5KB
ic_menu_about.png.svn-base 3KB
props
tmp
prop-base
text-base
props
entries 688B
ic_menu_about.png 3KB
icon.png 5KB
bin
resources.ap_ 26KB
SmsFilter.apk 37KB
.svn
props
tmp
props
entries 204B
classes.dex 18KB
com
pixtas
helper
DialogHelper.class 1KB
DatabaseAdapterHelper.class 4KB
DatabaseAdapterHelper$DatabaseHelper.class 1KB
smsfilter
R$string.class 827B
rest
RestAPI.class 3KB
R$layout.class 400B
activity
Main$2.class 860B
Main$1.class 1KB
Main.class 5KB
Main$3.class 839B
R$id.class 428B
service
SmsReceiver$1.class 1KB
SmsReceiver.class 7KB
SmsReceiver$mPhoneCallListener.class 2KB
R$attr.class 346B
R$color.class 426B
R$drawable.class 480B
Config.class 1KB
R.class 595B
proguard.cfg 1KB
.svn
prop-base
text-base
.project.svn-base 845B
AndroidManifest.xml.svn-base 1KB
default.properties.svn-base 362B
proguard.cfg.svn-base 1KB
.classpath.svn-base 280B
props
tmp
prop-base
text-base
props
entries 1002B
default.properties 362B
.project 845B
AndroidManifest.xml 1KB
gen
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 204B
com
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 211B
pixtas
.svn
prop-base
text-base
props
tmp
prop-base
text-base
props
entries 221B
smsfilter
.svn
prop-base
text-base
R.java.svn-base 2KB
props
tmp
prop-base
text-base
props
entries 358B
R.java 2KB
共 90 条
- 1
资源评论
大富大贵7
- 粉丝: 326
- 资源: 8864
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功