“第一次打开App,申请权限前”或“手机重启,未打开app”时,

MyApplication.SimInfoList可能为空
This commit is contained in:
miaoc 2021-07-16 11:01:00 +08:00
parent e98118d993
commit 48a7acf1cc
2 changed files with 15 additions and 7 deletions

View File

@ -10,9 +10,10 @@ import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import com.idormy.sms.forwarder.utils.OSUtils;
import com.idormy.sms.forwarder.utils.PhoneUtils;
import androidx.annotation.Nullable;
public class FrontService extends Service {
@ -60,6 +61,10 @@ public class FrontService extends Service {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
// 手机重启未打开app时主动获取SIM卡信息
if (MyApplication.SimInfoList.isEmpty()) {
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
}
}
@Nullable

View File

@ -18,9 +18,6 @@ import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.idormy.sms.forwarder.BroadCastReceiver.SmsForwarderBroadcastReceiver;
import com.idormy.sms.forwarder.adapter.LogAdapter;
import com.idormy.sms.forwarder.model.vo.LogVo;
@ -34,6 +31,9 @@ import com.umeng.analytics.MobclickAgent;
import java.util.ArrayList;
import java.util.List;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity implements ReFlashListView.IReflashListener {
ServiceConnection conn = new ServiceConnection() {
@ -73,8 +73,6 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
//获取SIM信息
PhoneUtils.init(this);
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
Log.d(TAG, "SimInfoList = " + MyApplication.SimInfoList);
//短信&网络组件初始化
SmsUtil.init(this);
@ -301,6 +299,11 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
//第一次打开申请权限前无法获取SIM信息尝试在此重新获取
if (MyApplication.SimInfoList.isEmpty()) {
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
}
Log.d(TAG, "SimInfoList = " + MyApplication.SimInfoList.size());
}
@Override