android 短信拦截器 代码

 今天利用广播机制给178折社区做了一个短信拦截器。在我做的这个拦截器中,可以有两种方式来设置拦截,一种是在AndroidManifest.xml直接设置拦截,另外一种是通过手动注册来设计拦截。在这里我们需要通过查文档找到短信收发的一些权限。
下面我附上自己做的这个拦截器的代码供大家参考。
main.xml layout
Java代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.    android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >   
  7. <Button     
  8.    android:layout_width="fill_parent"    
  9.     android:layout_height="wrap_content"    
  10.     android:text="注册拦截"  
  11.      android:onClick="regiset"  
  12.      />   
  13.  <Button     
  14.      android:layout_width="fill_parent"    
  15.      android:layout_height="wrap_content"    
  16.      android:text="解注册拦截"  
  17.      android:onClick="unregiset"  
  18.      />   
  19. </LinearLayout>  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button  
   android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="注册拦截"
     android:onClick="regiset"
     />
 <Button  
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="解注册拦截"
     android:onClick="unregiset"
     />
</LinearLayout>


首页显示的SmsListenerActivity:
Java代码
  1. package com.tk178zhe.android.SmsListener;   
  2.      
  3.   import android.app.Activity;   
  4.   import android.content.IntentFilter;   
  5.   import android.os.Bundle;   
  6.   import android.view.View;   
  7.   import android.widget.Toast;   
  8.      
  9.   public class SmsListenerActivity extends Activity {   
  10.      private SmsRecevier recevier;   
  11.      private boolean isregiset = false;   
  12.      private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";   
  13.     
  14.      @Override  
  15.      public void onCreate(Bundle savedInstanceState) {   
  16.          super.onCreate(savedInstanceState);   
  17.          setContentView(R.layout.main);   
  18.          recevier = new SmsRecevier();  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值