Skip to content

Commit

Permalink
新增在线升级、缓存清理、加入QQ群功能
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Feb 14, 2021
1 parent faed631 commit a02854b
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 55 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
| 转发Bark | 已实现,验证码/动态密码自动复制 |
| 转发企业微信群机器人 | 已实现 |
| 转发web页面 | 单个web页面已实现([向设置的url发送POST请求](doc/POST_WEB.md)|
| 转发规则 | (规则即:什么短信转发到哪里)已实现实现 |
| 转发规则 | (规则即:什么短信转发到哪里)已实现 |
| 兼容 | 已兼容6.xx、7.xx、8.xx、9.xx、10.xx |


### 使用流程:
1. 在Android手机上安装TSMS 本APP后点击应用图标打开
2. 在设置发送方页面,添加或点击已添加的发送方来设置转发短信使用的方式,现在支持钉钉机器人、邮箱、网页:
1. 在Android手机上安装SmsForwarder 本APP后点击应用图标打开
2. 在设置发送方页面,添加或点击已添加的发送方来设置转发短信使用的方式,现在支持钉钉机器人、企业微信群机器人、邮箱、网页、Bark
+ 设置钉钉机器人请先在钉钉群中添加自定义机器人,复制机器人的token和secret,填入弹出框。点击测试会使用该机器人向群内发送一条消息;点击确认即可添加配置。
+ 配置邮箱请先在你邮箱的后台管理页面配置smtp选项,并设置密码(授权码),并参照说明配置TSMS弹出框的smtp信息。点击测试会使用该邮箱向配置的邮箱发送一条测试邮件;点击确认即可添加配置。
+ 配置邮箱请先在你邮箱的后台管理页面配置smtp选项,并设置密码(授权码),并参照说明配置SmsForwarder弹出框的smtp信息。点击测试会使用该邮箱向配置的邮箱发送一条测试邮件;点击确认即可添加配置。
+ 配置网页通知请先在 msg.allmything.com 注册登陆并添加一个消息通道,复制消息通道token填入配置弹框。点击测试会向该消息通道推送一条测试消息,可在 msg.allmything.com 的消息页面查看(页面会自动刷新);点击确认即可添加配置。
3. 在设置转发规则页面,添加或点击已添加的转发规则来设置转发什么样的短信,现在支持转发全部、根据手机号、根据短信内容:
+ 当设置转发全部时,所以接收到的短信都会用转发出去。
Expand All @@ -74,10 +74,14 @@ Android手机监听短信并根据指定规则转发到其他手机、钉钉机
| ![添加编辑发送方邮箱](pic/sendersetemail.png "添加编辑发送方邮箱") | ![添加编辑发送方Bark](pic/sendersetbark.png "添加编辑发送方Bark") |
| ![添加编辑发送方网页通知](pic/sendersetwebnotify.png "添加编辑发送方网页通知") | ![添加编辑发送方企业微信群机器人](pic/sendersetqywechat.png "添加编辑发送方企业微信群机器人") |
| ![状态栏运行状态](pic/taskbar.png "状态栏运行状态") | ![应用设置](pic/setting.png "应用设置") |
| ![在线升级](pic/update.png "在线升级") | |

--------

## 更新记录:

> [v1.1.0](app/release/SmsForwarder_release_20210214_1.1.0.apk) 新增在线升级、缓存清理、加入QQ群功能
> [v1.0.0](app/release/SmsForwarder_release_20210213_1.0.0.apk) 优化后第一版

Expand Down
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.idormy.sms.forwarder"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
Expand All @@ -20,7 +20,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.2'
buildToolsVersion '28.0.3'
//apk file name
android.applicationVariants.all { variant ->
variant.outputs.all {
Expand Down Expand Up @@ -65,4 +65,9 @@ dependencies {
implementation "com.umeng.umsdk:common:9.3.6"
implementation "com.umeng.umsdk:asms:1.2.0"

//XUpdate
implementation 'com.github.xuexiangjys:XUpdate:2.0.7'
implementation 'com.github.xuexiangjys.XUpdateAPI:xupdate-easy:1.0.0'
implementation 'com.github.xuexiangjys.XUpdateAPI:xupdate-downloader-aria:1.0.0'

}
Binary file not shown.
6 changes: 3 additions & 3 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 1,
"versionName": "1.0.0",
"outputFile": "SmsForwarder_release_20210213_1.0.0.apk"
"versionCode": 2,
"versionName": "1.1.0",
"outputFile": "SmsForwarder_release_20210214_1.1.0.apk"
}
]
}
95 changes: 92 additions & 3 deletions app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
Expand All @@ -17,7 +19,10 @@
import androidx.appcompat.app.AppCompatActivity;

import com.idormy.sms.forwarder.BroadCastReceiver.RebootBroadcastReceiver;
import com.idormy.sms.forwarder.utils.CacheUtil;
import com.idormy.sms.forwarder.utils.aUtil;
import com.xuexiang.xupdate.easy.EasyUpdate;
import com.xuexiang.xupdate.proxy.impl.DefaultUpdateChecker;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -36,17 +41,75 @@ public void onCreate(Bundle savedInstanceState) {
Switch check_with_reboot = (Switch) findViewById(R.id.switch_with_reboot);
checkWithReboot(check_with_reboot);

TextView version_now = (TextView) findViewById(R.id.version_now);
final TextView version_now = (TextView) findViewById(R.id.version_now);
Button check_version_now = (Button) findViewById(R.id.check_version_now);
try {
version_now.setText(aUtil.getVersionName(SettingActivity.this));
} catch (Exception e) {
e.printStackTrace();
}

check_version_now.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
checkNewVersion();
//checkNewVersion();
try {
String updateUrl = "https://xupdate.bms.ink/update/checkVersion?appKey=com.idormy.sms.forwarder&versionCode=";
updateUrl += aUtil.getVersionCode(SettingActivity.this);

EasyUpdate.create(SettingActivity.this, updateUrl)
.updateChecker(new DefaultUpdateChecker() {
@Override
public void onBeforeCheck() {
super.onBeforeCheck();
Toast.makeText(SettingActivity.this, "查询中...", Toast.LENGTH_LONG).show();
}

@Override
public void onAfterCheck() {
super.onAfterCheck();
}

@Override
public void noNewVersion(Throwable throwable) {
super.noNewVersion(throwable);
// 没有最新版本的处理
Toast.makeText(SettingActivity.this, "已是最新版本!", Toast.LENGTH_LONG).show();
}
})
.update();
} catch (Exception e) {
e.printStackTrace();
}
}
});

final TextView cache_size = (TextView) findViewById(R.id.cache_size);
try {
cache_size.setText(CacheUtil.getTotalCacheSize(SettingActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
Button clear_all_cache = (Button) findViewById(R.id.clear_all_cache);
clear_all_cache.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CacheUtil.clearAllCache(SettingActivity.this);
try {
cache_size.setText(CacheUtil.getTotalCacheSize(SettingActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(SettingActivity.this, "缓存清理完成", Toast.LENGTH_LONG).show();
}
});

Button join_qq_group = (Button) findViewById(R.id.join_qq_group);
join_qq_group.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String key = "HvroJRfvK7GGfnQgaIQ4Rh1un9O83N7M";
joinQQGroup(key);
}
});

Expand Down Expand Up @@ -79,7 +142,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

private void checkNewVersion() {
try {

String updateUrl = "https://xupdate.bms.ink/update/checkVersion?appKey=com.idormy.sms.forwarder&versionCode=";
updateUrl += aUtil.getVersionCode(SettingActivity.this);
EasyUpdate.checkUpdate(SettingActivity.this, updateUrl);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -144,4 +209,28 @@ public void onError(String error) {
}).show();
}

/****************
*
* 发起添加群流程。群号:idormy 多米互联(562854376) 的 key 为: HvroJRfvK7GGfnQgaIQ4Rh1un9O83N7M
* 调用 joinQQGroup(HvroJRfvK7GGfnQgaIQ4Rh1un9O83N7M) 即可发起手Q客户端申请加群 idormy 多米互联(562854376)
*
* @param key 由官网生成的key
* @return 返回true表示呼起手Q成功,返回false表示呼起失败
******************/
public boolean joinQQGroup(String key) {
Intent intent = new Intent();
intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + key));
// 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
startActivity(intent);
return true;
} catch (Exception e) {
// 未安装手Q或安装的版本不支持
Toast.makeText(SettingActivity.this, "未安装手Q或安装的版本不支持!", Toast.LENGTH_LONG).show();
return false;
}
}


}
104 changes: 104 additions & 0 deletions app/src/main/java/com/idormy/sms/forwarder/utils/CacheUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.idormy.sms.forwarder.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.math.BigDecimal;

public class CacheUtil {
/**
* 获取缓存大小
*
* @param context
* @return
* @throws Exception
*/
public static String getTotalCacheSize(Context context) throws Exception {
long cacheSize = getFolderSize(context.getCacheDir());
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
cacheSize += getFolderSize(context.getExternalCacheDir());
}
return getFormatSize(cacheSize);
}

/***
* 清理所有缓存
* @param context
*/
public static void clearAllCache(Context context) {
deleteDir(context.getCacheDir());
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
deleteDir(context.getExternalCacheDir());
}
}

private static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}

// 获取文件
//Context.getExternalFilesDir() --> SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据
//Context.getExternalCacheDir() --> SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据
public static long getFolderSize(File file) throws Exception {
long size = 0;
try {
File[] fileList = file.listFiles();
for (int i = 0; i < fileList.length; i++) {
// 如果下面还有文件
if (fileList[i].isDirectory()) {
size = size + getFolderSize(fileList[i]);
} else {
size = size + fileList[i].length();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return size;
}

/**
* 格式化单位
*
* @param size
* @return
*/
public static String getFormatSize(double size) {
double kiloByte = size / 1024;
if (kiloByte < 1) {
return "0KB";
}

double megaByte = kiloByte / 1024;
if (megaByte < 1) {
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
}

double gigaByte = megaByte / 1024;
if (gigaByte < 1) {
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
}

double teraBytes = gigaByte / 1024;
if (teraBytes < 1) {
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
}

BigDecimal result4 = new BigDecimal(teraBytes);
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
}

}
Loading

0 comments on commit a02854b

Please sign in to comment.