1、短信模板增加卡槽标识(SIM-0_中国联通_Unknown 或 SIM-1_中国移动_+8615866666666)

2、转发日志详情增加卡槽标识(SIM1 或 SIM2)
pull/67/head
pppscn 3 years ago
parent a2e2d1dc41
commit b171dcb14e

3
.gitignore vendored

@ -9,4 +9,5 @@ local.properties
*.classpath
*/*.classpath
.settings/*
*/.settings/*
*/.settings/*
/app/pppscn.jks

@ -45,6 +45,7 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
- [x] 在线检测新版本、升级
- [x] 清理缓存
- [x] 兼容6.xx、7.xx、8.xx、9.xx、10.xx
- [x] 支持双卡手机,增加卡槽标识/运营商/手机号(如果能获取的话)
### 使用流程:
1. 在Android手机上安装SmsForwarder 本APP后点击应用图标打开
@ -72,13 +73,15 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
| ![添加编辑发送方邮箱](pic/sendersetemail.png "添加编辑发送方邮箱") | ![添加编辑发送方Bark](pic/sendersetbark.png "添加编辑发送方Bark") |
| ![添加编辑发送方网页通知](pic/sendersetwebnotify.png "添加编辑发送方网页通知") | ![添加编辑发送方企业微信群机器人](pic/sendersetqywechat.png "添加编辑发送方企业微信群机器人") |
| ![状态栏运行状态](pic/taskbar.png "状态栏运行状态") | ![应用设置](pic/setting.png "应用设置") |
| ![在线升级](pic/update.png "在线升级") | |
| ![在线升级](pic/update.png "在线升级") | ![转发日志详情增加卡槽标识](pic/siminfo.png "转发日志详情增加卡槽标识") |
--------
## 更新记录:
> [v1.2.2](app/release/SmsForwarder_release_20210302_1.2.2.apk) 【预发布】短信模板增加卡槽标识SIM1188xxxxxxxx 或 SIMxunknown
> [v1.2.3](app/release/SmsForwarder_release_20210302_1.2.3.apk) 转发日志详情增加卡槽标识SIM1 或 SIM2
> [v1.2.2](app/release/SmsForwarder_release_20210302_1.2.2.apk) 短信模板增加卡槽标识SIM-0_中国联通_Unknown 或 SIM-1_中国移动_+8615866666666
> [v1.2.1](app/release/SmsForwarder_release_20210226_1.2.1.apk) 修复bark-server升级到2.0后的兼容性问题

@ -14,14 +14,28 @@ android {
applicationId "com.idormy.sms.forwarder"
minSdkVersion 23
targetSdkVersion 28
versionCode 8
versionName "1.2.2"
versionCode 9
versionName "1.2.3"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
signingConfigs {
// C:\Users\<Username>\.gradle\gradle.properties
release {
storeFile file(RELEASE_STORE_FILE)
keyAlias RELEASE_KEY_ALIAS
storePassword RELEASE_KEY_PASSWORD
keyPassword RELEASE_STORE_PASSWORD
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
}
}
buildToolsVersion '29.0.2'

@ -10,9 +10,9 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 8,
"versionName": "1.2.2",
"outputFile": "SmsForwarder_release_20210302_1.2.2.apk"
"versionCode": 9,
"versionName": "1.2.3",
"outputFile": "SmsForwarder_release_20210302_1.2.3.apk"
}
]
}

@ -23,6 +23,7 @@ public class SmsForwarderBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String receiveAction = intent.getAction();
Log.d(TAG, "onReceive intent " + receiveAction);
if (receiveAction.equals("android.provider.Telephony.SMS_RECEIVED")) {
@ -33,15 +34,10 @@ public class SmsForwarderBroadcastReceiver extends BroadcastReceiver {
if (object != null) {
//获取接收手机号
String phoneNumber;
int solt = capturedSimSlot(extras);
Log.d("SIM_SLOT", " Slot Number " + solt);
if (solt == 1) {
MyApplication appContext = (MyApplication) context.getApplicationContext();
phoneNumber = "SIM1" + appContext.getLine1Number();
} else {
phoneNumber = "SIM" + solt + "unknown";
}
String simInfoId = String.valueOf(capturedSimSlot(extras));
Log.d("SIM_SLOT", " Slot Number " + simInfoId);
Map<String, String> sim = MyApplication.SimInfo.get(simInfoId);
String phoneNumber = "SIM-" + sim.get("sim_id") + "_" + sim.get("carrier_name") + "_" + sim.get("phone_number");
List<SmsVo> smsVoList = new ArrayList<>();
String format = intent.getStringExtra("format");
@ -80,14 +76,16 @@ public class SmsForwarderBroadcastReceiver extends BroadcastReceiver {
}
public int capturedSimSlot(Bundle bundle) {
//获取卡槽ID
private int capturedSimSlot(Bundle bundle) {
int whichSIM = -1;
if (bundle.containsKey("subscription")) {
whichSIM = bundle.getInt("subscription");
}
if (whichSIM >= 0 && whichSIM < 5) {
/*In some device Subscription id is return as subscriber id*/
return 1;
//TODO不确定能不能直接返回
return whichSIM;
}
if (bundle.containsKey("simId")) {
@ -106,4 +104,5 @@ public class SmsForwarderBroadcastReceiver extends BroadcastReceiver {
}
return whichSIM;
}
}

@ -1,11 +1,14 @@
package com.idormy.sms.forwarder;
import android.Manifest;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
@ -22,15 +25,14 @@ import androidx.core.app.ActivityCompat;
import com.idormy.sms.forwarder.BroadCastReceiver.SmsForwarderBroadcastReceiver;
import com.idormy.sms.forwarder.adapter.LogAdapter;
import com.idormy.sms.forwarder.model.LogModel;
import com.idormy.sms.forwarder.model.vo.LogVo;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.umeng.analytics.MobclickAgent;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity implements ReFlashListView.IReflashListener {
@ -41,6 +43,8 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
private List<LogVo> logVos = new ArrayList<>();
private LogAdapter adapter;
private ReFlashListView listView;
//SIM卡信息
//private Map<String, Map> SimInfo = new HashMap();
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -65,12 +69,15 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
//检查权限是否获取
checkPermission();
//获取本机号码
//获取本机号码(注意这里获取的不一定是卡槽1的)
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String Line1Number = mTelephonyMgr.getLine1Number();
Log.d(TAG, "Line1Number: " + Line1Number);
MyApplication appContext = ((MyApplication) getApplicationContext());
appContext.setLine1Number(Line1Number);
//获取SIM卡信息
getSimInfo(Line1Number);
//MyApplication appContext = ((MyApplication) getApplicationContext());
//appContext.setSimInfo(SimInfo);
}
// 初始化数据
@ -121,7 +128,12 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
public void logDetail(LogVo logVo) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("详情");
builder.setMessage(logVo.getFrom() + "\n\n" + logVo.getContent() + "\n\n" + logVo.getRule() + "\n\n" + logVo.getTime());
String simInfo = logVo.getSimInfo();
if (simInfo != null) {
builder.setMessage(logVo.getFrom() + "\n\n" + logVo.getContent() + "\n\n" + logVo.getSimInfo() + "\n\n" + logVo.getRule() + "\n\n" + logVo.getTime());
} else {
builder.setMessage(logVo.getFrom() + "\n\n" + logVo.getContent() + "\n\n" + logVo.getRule() + "\n\n" + logVo.getTime());
}
builder.show();
}
@ -158,14 +170,6 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
}
public void addLog(View view) {
Log.d(TAG, "refreshLog");
LogModel newModel = new LogModel("199999", "content" + (new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(new Date())), 1l);
LogUtil.addLog(newModel);
// initTLogs();
// adapter.add(logVos);
}
//按返回键不退出回到桌面
@Override
public void onBackPressed() {
@ -225,4 +229,33 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
MobclickAgent.onPause(this);
}
//获取SIM卡信息
private void getSimInfo(String Line1Number) {
Uri uri = Uri.parse("content://telephony/siminfo"); //访问raw_contacts表
MyApplication appContext = ((MyApplication) getApplicationContext());
ContentResolver resolver = appContext.getContentResolver();
Cursor cursor = resolver.query(uri, new String[]{"_id", "icc_id", "sim_id", "display_name", "carrier_name", "name_source", "color", "number", "display_number_format", "data_roaming", "mcc", "mnc"}, "sim_id >= 0", null, "_id");
if (cursor != null) {
while (cursor.moveToNext()) {
Log.d(TAG, "_id: " + cursor.getString(cursor.getColumnIndex("_id")));
Log.d(TAG, "sim_id: " + cursor.getString(cursor.getColumnIndex("sim_id")));
Log.d(TAG, "carrier_name: " + cursor.getString(cursor.getColumnIndex("carrier_name")));
Log.d(TAG, "display_name: " + cursor.getString(cursor.getColumnIndex("display_name")));
Map<String, String> sim = new HashMap();
String id = cursor.getString(cursor.getColumnIndex("_id"));
sim.put("_id", id);
sim.put("sim_id", cursor.getString(cursor.getColumnIndex("sim_id")));
sim.put("carrier_name", cursor.getString(cursor.getColumnIndex("carrier_name")));
sim.put("display_name", cursor.getString(cursor.getColumnIndex("display_name")));
sim.put("phone_number", Line1Number);
if (Line1Number != "Unknown") {
Line1Number = "Unknown";
}
MyApplication.SimInfo.put(id, sim);
}
cursor.close();
Log.d(TAG, String.valueOf(MyApplication.SimInfo.get("2").get("sim_id")));
}
}
}

@ -15,9 +15,13 @@ import com.smailnet.emailkit.EmailKit;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import java.util.HashMap;
import java.util.Map;
public class MyApplication extends Application {
private static final String TAG = "MyApplication";
private String Line1Number;
//SIM卡信息
public static Map<String, Map> SimInfo = new HashMap();
/**
* <meta-data
@ -55,12 +59,12 @@ public class MyApplication extends Application {
return channelName;
}
public String getLine1Number() {
return Line1Number;
public Map<String, Map> getSimInfo() {
return SimInfo;
}
public void setLine1Number(String s) {
Line1Number = s;
public void setSimInfo(Map<String, Map> info) {
SimInfo = info;
}
@Override

@ -5,10 +5,12 @@ public class LogModel {
private String content;
private Long ruleId;
private Long time;
private String simInfo;
public LogModel(String from, String content, Long ruleId) {
public LogModel(String from, String content, String simInfo, Long ruleId) {
this.from = from;
this.content = content;
this.simInfo = simInfo;
this.ruleId = ruleId;
}
@ -28,6 +30,14 @@ public class LogModel {
this.content = content;
}
public String getSimInfo() {
return simInfo;
}
public void setSimInfo(String simInfo) {
this.simInfo = simInfo;
}
public Long getRuleId() {
return ruleId;
}
@ -40,11 +50,16 @@ public class LogModel {
return time;
}
public void setTime(Long time) {
this.time = time;
}
@Override
public String toString() {
return "LogModel{" +
"from='" + from + '\'' +
", content='" + content + '\'' +
", simInfo=" + simInfo +
", ruleId=" + ruleId +
", time=" + time +
'}';

@ -15,5 +15,6 @@ public final class LogTable {
public static final String COLUMN_NAME_CONTENT = "content";
public static final String COLUMN_NAME_RULE_ID = "rule_id";
public static final String COLUMN_NAME_TIME = "time";
public static final String COLUMN_NAME_SIM_INFO = "sim_info";
}
}

@ -3,13 +3,15 @@ package com.idormy.sms.forwarder.model.vo;
public class LogVo {
private String from;
private String content;
private String simInfo;
private String rule;
private int senderImageId;
private String time;
public LogVo(String from, String content, String time, String rule, int senderImageId) {
public LogVo(String from, String content, String simInfo, String time, String rule, int senderImageId) {
this.from = from;
this.content = content;
this.simInfo = simInfo;
this.time = time;
this.rule = rule;
this.senderImageId = senderImageId;
@ -35,6 +37,14 @@ public class LogVo {
this.content = content;
}
public String getSimInfo() {
return simInfo;
}
public void setSimInfo(String simInfo) {
this.simInfo = simInfo;
}
public String getRule() {
return rule;
}

@ -15,7 +15,7 @@ import java.util.List;
public class DbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final String TAG = "DbHelper";
public static final int DATABASE_VERSION = 1;
public static final int DATABASE_VERSION = 2;
public static final String DATABASE_NAME = "sms_forwarder.db";
private static final List<String> SQL_CREATE_ENTRIES =
@ -24,6 +24,7 @@ public class DbHelper extends SQLiteOpenHelper {
LogTable.LogEntry._ID + " INTEGER PRIMARY KEY," +
LogTable.LogEntry.COLUMN_NAME_FROM + " TEXT," +
LogTable.LogEntry.COLUMN_NAME_CONTENT + " TEXT," +
LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " TEXT," +
LogTable.LogEntry.COLUMN_NAME_RULE_ID + " INTEGER," +
LogTable.LogEntry.COLUMN_NAME_TIME + " TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"
, "CREATE TABLE " + RuleTable.RuleEntry.TABLE_NAME + " (" +
@ -74,8 +75,12 @@ public class DbHelper extends SQLiteOpenHelper {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// This database is only a cache for online data, so its upgrade policy is
// to simply to discard the data and start over
delCreateTable(db);
onCreate(db);
//delCreateTable(db);
//onCreate(db);
if (oldVersion < 2) { //当数据库版本小于版本2时
String sql = "Alter table " + LogTable.LogEntry.TABLE_NAME + " add column " + LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " TEXT ";
db.execSQL(sql);
}
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

@ -48,6 +48,7 @@ public class LogUtil {
ContentValues values = new ContentValues();
values.put(LogTable.LogEntry.COLUMN_NAME_FROM, logModel.getFrom());
values.put(LogTable.LogEntry.COLUMN_NAME_CONTENT, logModel.getContent());
values.put(LogTable.LogEntry.COLUMN_NAME_SIM_INFO, logModel.getSimInfo());
values.put(LogTable.LogEntry.COLUMN_NAME_RULE_ID, logModel.getRuleId());
// Insert the new row, returning the primary key value of the new row
@ -89,6 +90,7 @@ public class LogUtil {
LogTable.LogEntry.TABLE_NAME + "." + LogTable.LogEntry.COLUMN_NAME_FROM + " AS " + LogTable.LogEntry.COLUMN_NAME_FROM,
LogTable.LogEntry.TABLE_NAME + "." + LogTable.LogEntry.COLUMN_NAME_TIME + " AS " + LogTable.LogEntry.COLUMN_NAME_TIME,
LogTable.LogEntry.TABLE_NAME + "." + LogTable.LogEntry.COLUMN_NAME_CONTENT + " AS " + LogTable.LogEntry.COLUMN_NAME_CONTENT,
LogTable.LogEntry.TABLE_NAME + "." + LogTable.LogEntry.COLUMN_NAME_SIM_INFO + " AS " + LogTable.LogEntry.COLUMN_NAME_SIM_INFO,
RuleTable.RuleEntry.TABLE_NAME + "." + RuleTable.RuleEntry.COLUMN_NAME_FILED + " AS " + RuleTable.RuleEntry.COLUMN_NAME_FILED,
RuleTable.RuleEntry.TABLE_NAME + "." + RuleTable.RuleEntry.COLUMN_NAME_CHECK + " AS " + RuleTable.RuleEntry.COLUMN_NAME_CHECK,
RuleTable.RuleEntry.TABLE_NAME + "." + RuleTable.RuleEntry.COLUMN_NAME_VALUE + " AS " + RuleTable.RuleEntry.COLUMN_NAME_VALUE,
@ -143,6 +145,8 @@ public class LogUtil {
cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_FROM));
String content = cursor.getString(
cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_CONTENT));
String simInfo = cursor.getString(
cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_SIM_INFO));
String time = cursor.getString(
cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_TIME));
String ruleFiled = cursor.getString(
@ -158,10 +162,9 @@ public class LogUtil {
Log.d(TAG, "getLog: time" + time);
String rule = RuleModel.getRuleMatch(ruleFiled, ruleCheck, ruleValue) + senderName;
// String rule = time+" 转发到 "+senderName;
int senderImageId = SenderModel.getImageId(senderType);
LogVo logVo = new LogVo(itemfrom, content, time, rule, senderImageId);
int senderImageId = SenderModel.getImageId(senderType);
LogVo logVo = new LogVo(itemfrom, content, simInfo, time, rule, senderImageId);
LogVos.add(logVo);
} catch (Exception e) {
Log.i(TAG, "getLog e:" + e.getMessage());
@ -169,7 +172,6 @@ public class LogUtil {
}
cursor.close();
return LogVos;

@ -138,7 +138,7 @@ public class SendUtil {
List<SenderModel> senderModels = SenderUtil.getSender(ruleModel.getSenderId(), null);
for (SenderModel senderModel : senderModels
) {
LogUtil.addLog(new LogModel(smsVo.getMobile(), smsVo.getContent(), senderModel.getId()));
LogUtil.addLog(new LogModel(smsVo.getMobile(), smsVo.getContent(), smsVo.getPhoneNumber(), senderModel.getId()));
SendUtil.senderSendMsg(smsVo, senderModel);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

Loading…
Cancel
Save