大家好,我编写的应用程序应读取任何新的短信并添加到我的数据库中,但是我的应用程序多次读取无穷大的消息,我不知道是什么问题,当应用程序在后台或应用程序时我想要什么关闭,也阅读了新的短信,但不幸的是没有阅读,请任何人帮助我,我将非常感谢他/她
public void refreshSmsInbox() {
ContentResolver contentResolver = getContentResolver();
smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"), null, null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
// must check the result to prevent exception
if(smsInboxCursor.moveToFirst())
if (smsInboxCursor.getString(indexAddress).equals(".Samba")) {
smsbody = smsInboxCursor.getString(indexBody);
int end = smsbody.indexOf(' ');
transaction = smsbody.substring(0, end);
if (transaction.equals("دفع")) {
type = "outflow";
smsoutflow();
smsInboxCursor.close();
return;
} else if (transaction.equals("تم")) {
type = "inflow";
smsinflow();
smsInboxCursor.close();
return;
} else if (transaction.equals("سحب")) {
type = "outflowATM";
smsoutflowATM();
smsInboxCursor.close();
return;
}
} smsInboxCursor.close();
}
public void smsoutflow(){
if(type.equals("outflow")) {
myRef11 = FirebaseDatabase.getInstance().getReference("user_account").child("(username)").child("bank_accounts");
int accountnumberstart = smsbody.lastIndexOf(".");
count = accountnumberstart + 5;
accountnumber = smsbody.substring(accountnumberstart + 2, count);
myRef11.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//Take last three number card number
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (ds.child("account_no").exists()) {
toastMessage(ds.getKey());
String dataaccountOUT = ds.child("account_no").getValue(String.class);
if (Integer.parseInt(accountnumber) == Integer.parseInt(dataaccountOUT)) {
String bank = ds.getKey();
bank2 = bank;
equles = true;
break;
}
}
}
addoutflow(bank2);
return;
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}