mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-15 18:13:57 +00:00
Android8.1以下手机重启后尝试启动主界面,以便动态获取权限
This commit is contained in:
parent
0c3865b5d2
commit
bb585be267
@ -76,6 +76,8 @@
|
||||
|
||||
> 近期接收到部分用户反馈,`SmsForwarder`无法正确转发通知类短信,涉及 ROM 有华为 EMUI 和 小米 MIUI。这两个系统提供了验证类短信安全保护功能,导致验证码不能正常通过广播获得。以下是解决方案。
|
||||
|
||||
> ⚠ 风险警示:转发验证码可能导致您的个人隐私、账户安全受到损害,如果您已经知晓该风险,请继续进行以下操作。
|
||||
|
||||
> 华为 EMUI:
|
||||
|
||||
> 信息 > 更多 > 设置 > 高级 关闭验证码安全保护开关。
|
||||
@ -143,7 +145,7 @@
|
||||
|
||||
* 与 @BotFather 私聊,申请 Bot
|
||||
* /newbot 后输入机器人昵称
|
||||
* 然后输入机器人的用户名(建议:使用密码生成器生成随机字符串,避免一直重复尝试)
|
||||
* 然后输入机器人的用户名(建议:使用密码生成器生成随机字符串,避免一直重复尝试;用户名必须用 bot 作为结尾)
|
||||
* /token 获取apiToken,然后输入上面机器人的用户名
|
||||
* 获得apiToken,格式参考:1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
* 复制 apiToken 到「设置Telegram机器人的ApiToken」一栏
|
||||
@ -201,6 +203,7 @@
|
||||
+ [v1.6.1](app/release/SmsForwarder_release_20210312_1.6.1.apk) 新增转发到Server酱·Turbo版
|
||||
+ [v1.6.2](app/release/SmsForwarder_release_20210312_1.6.2.apk) 新增转发到Telegram机器人
|
||||
+ [v1.6.3](app/release/SmsForwarder_release_20210313_1.6.3.apk) 转发到webhook支持GET方式(节点改变,原配置要重新编辑);兼容Android5.0(待验证,仅minSdkVersion改为21);修复钉钉机器人没启用加签时url拼接错误问题
|
||||
+ [v1.6.3](app/release/SmsForwarder_release_20210313_1.6.4.apk) 修复开机自启后无法转发短信,要打开软件后才会转发短信的问题
|
||||
|
||||
--------
|
||||
|
||||
|
BIN
app/release/SmsForwarder_release_20210314_1.6.4.apk
Normal file
BIN
app/release/SmsForwarder_release_20210314_1.6.4.apk
Normal file
Binary file not shown.
@ -10,9 +10,9 @@
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"versionCode": 19,
|
||||
"versionName": "1.6.3",
|
||||
"outputFile": "SmsForwarder_release_20210313_1.6.3.apk"
|
||||
"versionCode": 20,
|
||||
"versionName": "1.6.4",
|
||||
"outputFile": "SmsForwarder_release_20210314_1.6.4.apk"
|
||||
}
|
||||
]
|
||||
}
|
@ -6,6 +6,7 @@ import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
@ -49,6 +50,16 @@ public class FrontService extends Service {
|
||||
|
||||
Notification notification = builder.build();
|
||||
startForeground(1, notification);
|
||||
|
||||
//检查权限是否获取
|
||||
//PackageManager pm = getPackageManager();
|
||||
//PhoneUtils.CheckPermission(pm, this);
|
||||
|
||||
//Android8.1以下尝试启动主界面,以便动态获取权限
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.idormy.sms.forwarder;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -18,7 +20,6 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.idormy.sms.forwarder.BroadCastReceiver.SmsForwarderBroadcastReceiver;
|
||||
import com.idormy.sms.forwarder.adapter.LogAdapter;
|
||||
@ -33,6 +34,20 @@ import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements ReFlashListView.IReflashListener {
|
||||
|
||||
ServiceConnection conn = new ServiceConnection() {
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
// 当service绑定成功时,会调用次方法,可以在此申请权限
|
||||
PackageManager pm = getPackageManager();
|
||||
PhoneUtils.CheckPermission(pm, MainActivity.this);
|
||||
}
|
||||
};
|
||||
private IntentFilter intentFilter;
|
||||
private SmsForwarderBroadcastReceiver smsBroadcastReceiver;
|
||||
private String TAG = "MainActivity";
|
||||
@ -43,6 +58,7 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
LogUtil.init(this);
|
||||
Log.d(TAG, "oncreate");
|
||||
|
||||
@ -50,7 +66,8 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
//检查权限是否获取
|
||||
checkPermission();
|
||||
PackageManager pm = getPackageManager();
|
||||
PhoneUtils.CheckPermission(pm, this);
|
||||
|
||||
//获取SIM信息
|
||||
PhoneUtils.init(this);
|
||||
@ -219,39 +236,6 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
// 检查权限是否获取(android6.0及以上系统可能默认关闭权限,且没提示)
|
||||
private void checkPermission() {
|
||||
PackageManager pm = getPackageManager();
|
||||
boolean permission_internet = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.INTERNET", this.getPackageName()));
|
||||
boolean permission_receive_boot = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.RECEIVE_BOOT_COMPLETED", this.getPackageName()));
|
||||
boolean permission_foreground_service = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.FOREGROUND_SERVICE", this.getPackageName()));
|
||||
boolean permission_read_external_storage = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_EXTERNAL_STORAGE", this.getPackageName()));
|
||||
boolean permission_write_external_storage = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", this.getPackageName()));
|
||||
boolean permission_receive_sms = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.RECEIVE_SMS", this.getPackageName()));
|
||||
boolean permission_read_sms = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_SMS", this.getPackageName()));
|
||||
boolean permission_send_sms = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.SEND_SMS", this.getPackageName()));
|
||||
boolean permission_read_phone_state = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_PHONE_STATE", this.getPackageName()));
|
||||
boolean permission_read_phone_numbers = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_PHONE_NUMBERS", this.getPackageName()));
|
||||
|
||||
if (!(permission_internet && permission_receive_boot && permission_foreground_service &&
|
||||
permission_read_external_storage && permission_write_external_storage &&
|
||||
permission_receive_sms && permission_read_sms && permission_send_sms &&
|
||||
permission_read_phone_state && permission_read_phone_numbers)) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{
|
||||
Manifest.permission.INTERNET,
|
||||
Manifest.permission.RECEIVE_BOOT_COMPLETED,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.RECEIVE_SMS,
|
||||
Manifest.permission.READ_SMS,
|
||||
Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.READ_PHONE_NUMBERS,
|
||||
Manifest.permission.FOREGROUND_SERVICE,
|
||||
}, 0x01);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle item selection
|
||||
|
@ -2,6 +2,7 @@ package com.idormy.sms.forwarder.utils;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
@ -524,6 +525,39 @@ public class PhoneUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
// 检查权限是否获取(android6.0及以上系统可能默认关闭权限,且没提示)
|
||||
public static void CheckPermission(PackageManager pm, Context that) {
|
||||
//PackageManager pm = getPackageManager();
|
||||
boolean permission_internet = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.INTERNET", that.getPackageName()));
|
||||
boolean permission_receive_boot = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.RECEIVE_BOOT_COMPLETED", that.getPackageName()));
|
||||
boolean permission_foreground_service = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.FOREGROUND_SERVICE", that.getPackageName()));
|
||||
boolean permission_read_external_storage = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_EXTERNAL_STORAGE", that.getPackageName()));
|
||||
boolean permission_write_external_storage = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", that.getPackageName()));
|
||||
boolean permission_receive_sms = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.RECEIVE_SMS", that.getPackageName()));
|
||||
boolean permission_read_sms = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_SMS", that.getPackageName()));
|
||||
boolean permission_send_sms = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.SEND_SMS", that.getPackageName()));
|
||||
boolean permission_read_phone_state = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_PHONE_STATE", that.getPackageName()));
|
||||
boolean permission_read_phone_numbers = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_PHONE_NUMBERS", that.getPackageName()));
|
||||
|
||||
if (!(permission_internet && permission_receive_boot && permission_foreground_service &&
|
||||
permission_read_external_storage && permission_write_external_storage &&
|
||||
permission_receive_sms && permission_read_sms && permission_send_sms &&
|
||||
permission_read_phone_state && permission_read_phone_numbers)) {
|
||||
ActivityCompat.requestPermissions((Activity) that, new String[]{
|
||||
Manifest.permission.INTERNET,
|
||||
Manifest.permission.RECEIVE_BOOT_COMPLETED,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.RECEIVE_SMS,
|
||||
Manifest.permission.READ_SMS,
|
||||
Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.READ_PHONE_NUMBERS,
|
||||
Manifest.permission.FOREGROUND_SERVICE,
|
||||
}, 0x01);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SIM 卡信息
|
||||
*/
|
||||
@ -598,5 +632,4 @@ public class PhoneUtils {
|
||||
super(info);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
ext {
|
||||
appVersionCode = 19
|
||||
appVersionName = "1.6.3"
|
||||
appVersionCode = 20
|
||||
appVersionName = "1.6.4"
|
||||
}
|
Loading…
Reference in New Issue
Block a user