Android 截取指定号码的短信 并且不让系统获取短信通知用户
2013-04-25 22:50
621 查看
之前在做黑名单屏蔽短信的时候,遇到一个比较棘手的问题,就是我截取我指定号码的短信之后,但是我如何不让系统通过通知栏通知用户,在网上也寻找了很久,也有点眉目了,以下是别人使用 ContentObserver 来监听短信数据库变化来实现的。
Java 代码
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* Android.permission.READ_SMS
读取短信
* android.permission.WRITE_SMS 写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
第1页 第2页 第3页 第4页
之前在做黑名单屏蔽短信的时候,遇到一个比较棘手的问题,就是我截取我指定号码的短信之后,但是我如何不让系统通过通知栏通知用户,在网上也寻找了很久,也有点眉目了,以下是别人使用 ContentObserver 来监听短信数据库变化来实现的。
Java 代码
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS 读取短信
* android.permission.WRITE_SMS 写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
第1页 第2页 第3页 第4页
接上页
true, content);
}
}
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS读取短信
* android.permission.WRITE_SMS写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
}
}
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
第1页 第2页 第3页 第4页
接上页
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS 读取短信
* android.permission.WRITE_SMS 写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
true, content);
}
}
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
第1页 第2页 第3页 第4页
接上页
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS读取短信
* android.permission.WRITE_SMS写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
}
}
Java 代码
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* Android.permission.READ_SMS
读取短信
* android.permission.WRITE_SMS 写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
第1页 第2页 第3页 第4页
之前在做黑名单屏蔽短信的时候,遇到一个比较棘手的问题,就是我截取我指定号码的短信之后,但是我如何不让系统通过通知栏通知用户,在网上也寻找了很久,也有点眉目了,以下是别人使用 ContentObserver 来监听短信数据库变化来实现的。
Java 代码
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS 读取短信
* android.permission.WRITE_SMS 写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
第1页 第2页 第3页 第4页
接上页
true, content);
}
}
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS读取短信
* android.permission.WRITE_SMS写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
}
}
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
第1页 第2页 第3页 第4页
接上页
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS 读取短信
* android.permission.WRITE_SMS 写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
true, content);
}
}
public class ScreenTest extends Activity {
class SmsContent extends ContentObserver{
private Cursor cursor = null;
public SmsContent(Handler handler) {
super(handler);
}
/**
第1页 第2页 第3页 第4页
接上页
* @Description 当短信表发送改变时,调用该方法
* 需要两种权限
* android.permission.READ_SMS读取短信
* android.permission.WRITE_SMS写短信
* @Author Snake
* @Date 2010-1-12
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
//读取收件箱中指定号码的短信
cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
if (cursor != null){
ContentValues values = new ContentValues();
values.put("read", "1"); //修改短信为已读模式
cursor.moveToFirst();
while (cursor.isLast()){
//更新当前未读短信状态为已读
getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
cursor.moveToNext();
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsContent content = new SmsContent(new Handler());
//注册短信变化监听
this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
}
}
相关文章推荐
- Android 截取指定号码的短信,并且不让系统获取短信通知用户
- Android使用ContentObserver监听数据库变化 接受指定号码的短信,并且不让系统截取到通知用户
- Android使用ContentObserver监听数据库变化 接受指定号码的短信,并且不让系统截取到通知用户
- 接受指定号码的短信,并且不让系统截取到通知用户
- 如何截取指定号码的短信,并且不让系统截取到通知用户
- Android使用ContentObserver监听数据库变化,截取系统通知用户接收到短信
- Android 调用系统发短信界面,给指定号码发短信,并带短信内容
- Android 调用系统发短信界面,给指定号码发短信,并带短信内容
- Android应用获取通知栏权限是否开启--以及跳转到系统设置界面--解决方案
- Android 获取imei号码,获取手机型号和系统版本号
- Android 获取系统信息 手机号码 所在国家码
- android调用系统短信Intent时将预填接收号码
- android黑科技之读取用户短信+插入短信到系统短信数据库
- 【实验】给指定的并且已登陆系统的用户发信息
- android_71_获取系统短信
- Android 获取imei号码,获取手机型号和系统版本号
- iOS获取系统短信,发送指定短信内容
- Android系统获取用户来电信息
- android 获取一些系统指定路径的方法整理
- 伪基站收集方圆500至1000米范围内的手机卡信息,并且通过伪基站设备伪装成银行、中国移动、中国联通等任意号码向手机用户发送短信或拨打电话