Skip to content

Commit

Permalink
优化短信接收
Browse files Browse the repository at this point in the history
  • Loading branch information
zhinianblog committed Apr 28, 2024
1 parent 25ab428 commit 97e1b48
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/com/iwhalecloud/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnI

private String serverUrl;

private Boolean isInit = true;

//定义下拉列表需要显示的文本数组
private final static String[] starArray = {"ark.leafxxx.win", "login.ouklc.com", "jd.222798.xyz"};

Expand Down Expand Up @@ -216,7 +218,14 @@ public void onItemSelected(AdapterView<?> adapterView, View view, int position,
serverUrl = starArray[position];

TextView v3 = findViewById(R.id.editText3);
v3.setText(serverUrl);
String selfUrl = v3.getText().toString();
if(!serverUrl.equals(selfUrl) && !isInit) {
v3.setText(serverUrl);
}
else if(!selfUrl.isEmpty()){
serverUrl = selfUrl;
}
isInit = false;
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/iwhalecloud/demo/SMS/MyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class MyService extends Service {

private List<String> smsUrlList = new ArrayList<>();

private List<String> yanzhengmaList = new ArrayList<>();
private String message;

@Override
Expand Down Expand Up @@ -316,6 +317,11 @@ private void setSmsCode() {
null, null, "_id desc");
if (cursor != null) {
cursor.moveToFirst();
String[] columnNames = cursor.getColumnNames();
for(String asdf: columnNames ) {
Log.d(TAG, "key值" + asdf);
Log.d(TAG, "key值" + cursor.getString(cursor.getColumnIndex(asdf)));
}
final String strBody = cursor.getString(cursor.getColumnIndex("body")); // 在这里获取短信信息

if(strBody != null && strBody.contains("京东")) {
Expand All @@ -326,6 +332,12 @@ private void setSmsCode() {
dynamicPassword = m.group();
}
String finalDynamicPassword = dynamicPassword;
if(yanzhengmaList.contains(finalDynamicPassword)) {
return;
}
else {
yanzhengmaList.add(finalDynamicPassword);
}
new Thread(new Runnable() {
@Override
public void run() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.1.4版本"
android:text="1.1.5版本"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="38dp" />

Expand Down

0 comments on commit 97e1b48

Please sign in to comment.