Uri 查询短信以获取今天发送的短信计数



我正在从code发送SMS,并更新Systems短信Sent消息;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
{
int subscriptionId = SmsManager.getDefaultSmsSubscriptionId();
SmsManager MySmsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
ArrayList<String> msgArray = MySmsManager.divideMessage(DefaultMsgTemplate);
MySmsManager.sendMultipartTextMessage(SendSMSTo, null,msgArray, null, null);
CurrentSmsParts = msgArray.size();
Log.d("SMS DETAILS : ", "nFOUND LOLLIPOP MR1 OR ABOVE...");
Log.d("SMS DETAILS : ", "nDETECTED DEFAULT SMS SIM..."+subscriptionId);
Log.d("SMS DETAILS : ", "nSENT MSG USING SIM..."+subscriptionId);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
{
SmsManager MySmsManager = SmsManager.getDefault();
ArrayList<String> msgArray = MySmsManager.divideMessage(DefaultMsgTemplate);
MySmsManager.sendMultipartTextMessage(SendSMSTo, null,msgArray, null, null);
CurrentSmsParts = msgArray.size();
Log.d("SMS DETAILS : ", "nFOUND BELOW LOLLIPOP MR1...");
Log.d("SMS DETAILS : ", "nDETECTED DEFAULT SMS SIM WHICHEVER AVAILABLE...");
Log.d("SMS DETAILS : ", "nSENT MSG USING SIM1 OR SIM2 WHICHEVER IS AVAILABLE...");
}

ContentValues values = new ContentValues();
values.put("address", SendSMSTo);
values.put("body", DefaultMsgTemplate);
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
SMSDone++;

这是我通过我的应用程序计算today sent SMSsSMSDonecounter... ;But Users are also able to send SMSs, without my application..!!

所以。。

  1. 如何查询短信 uri 以获取今天发送的两张 SIM 卡/号码的短信号码?
  2. 我正在将我的短信插入已发送短信中;但是,如何从我的应用程序中插入发送SIM卡号码?

学分:迈克·

按照他的指示进行操作,并通过具有早期 uri 查询的基础知识,这是我实现的最终答案......

Log.d("Executing :", "from here....n");
try 
{
Calendar c1 = Calendar.getInstance();
c1.setTime(new Date());
Calendar c2 = Calendar.getInstance();
c2.set(Calendar.YEAR, c1.get(Calendar.YEAR));
c2.set(Calendar.MONTH, c1.get(Calendar.MONTH));
c2.set(Calendar.DAY_OF_MONTH, c1.get(Calendar.DAY_OF_MONTH));
c2.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.SECOND, 0);
long TodayStartedAt = c2.getTimeInMillis();
Log.d("Today started at ", "here" + TodayStartedAt);
final Uri SMS_INBOX = Uri.parse("content://sms/sent");
Cursor cursor = getContentResolver().query(SMS_INBOX, null, "date>=" + TodayStartedAt, null, null);
List < String > items = new ArrayList < String > ();
int counter = 0;
while (cursor.moveToNext()) 
{
String Date = cursor.getString(cursor.getColumnIndex("date"));
String SmsBody = cursor.getString(cursor.getColumnIndex("body"));
String PhoneNumber = cursor.getString(cursor.getColumnIndex("address"));
String FromSIM = cursor.getString(cursor.getColumnIndex("sub_id"));
Log.d("Counter : ", counter + "n");
Log.d("Date : ", Date + "n");
Log.d("PhoneNumber : ", PhoneNumber + "n");
Log.d("FromSIM : ", FromSIM + "n");
Log.d("SmsBody : ", SmsBody + "n");
counter++;
}
cursor.close();
} 
catch (Exception e) 
{
Log.e("exception :", "is", e);
}

谢谢@Mike M。并发布,因为它将来可能会帮助其他人...

最新更新