下面的代码将显示最后一周的通话记录详细信息。但我想将该通话记录详细信息发送到我的gmail-id“jegadesh9531@gmail.com。有人请告诉我,我必须做些什么改变用于将呼叫日志详细信息发送到我的电子邮件的代码。
private String getCallDetails()
{
StringBuffer stringBuffer = new StringBuffer();
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, -7);
Date weekBefore = calendar.getTime();
String selection = android.provider.CallLog.Calls.DATE + ">?";
String [] selectionArgs = {String.valueOf(weekBefore.getTime())};
Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null, selection, selectionArgs, CallLog.Calls.DATE + " DESC");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED)
{
}
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
stringBuffer.append("Call Log :");
while (managedCursor.moveToNext())
{
String phoneNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
SimpleDateFormat formatter = new SimpleDateFormat(
"dd-MMM-yyyy HH:mm");
String dateString = formatter.format(new Date(Long
.parseLong(callDate)));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dirCode = Integer.parseInt(callType);
switch (dirCode)
{
case CallLog.Calls.OUTGOING_TYPE :
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED CALL";
break;
}
stringBuffer.append("\nPhone Number:--- " + phoneNumber + "\nCall Type:--- "
+ dir + "\nCall Date:---"
+ dateString + "\nCall Duration:---" + callDuration);
stringBuffer.append("\n--------------------------");
}
managedCursor.close();
return stringBuffer.toString();
}
答案 0 :(得分:0)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "jegadesh9531@gmail.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Hi,");
intent.putExtra(Intent.EXTRA_TEXT, "Call Logs "+stringBuffer.toString());
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Send Email"));
我希望它能帮到你:)。