我是android studio的新手。我正在开发一个应用程序,该应用程序使用传入的短信命中网址并且其正常工作正在运行代码
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message);
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, "senderNum: " + senderNum + ", message: " + message, duration);
toast.show();
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat df2 = new SimpleDateFormat("HH:mm");
String cDate = df1.format(Calendar.getInstance().getTime());
String cTime = df2.format(Calendar.getInstance().getTime());
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String ime = tm.getDeviceId();
useGet(ime, cDate, cTime, "0", senderNum, message);
}
}
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" +e);
}
但是我想保留收件箱短信或它已经点击网址的索引,以避免重复点击,以防短信没有点击网址,用户通过点击按钮手动回击。
答案 0 :(得分:0)
将这些详细信息保存在本地数据库中,并在点击网址之前验证它是否已经完成