私のプロジェクトでは、通話ログと SMS データを取得し、バックグラウンドで電子メールで送信したいと考えています。取得したデータ コードは次のとおりです:-(WakefulBroadcastReceiver 内)
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
getSMSData();
getCallLogData();
}
private void getSMSData() {
ContentResolver contentResolver = mContext.getContentResolver();
// use content://sms/inbox/ for received and content://sms/sent/ for sent messages
Uri uri = Uri.parse("content://sms/");
String selection = "date BETWEEN ? AND ? ";
long currentTime = System.currentTimeMillis();
long pastThreeHour = currentTime - (AlarmManager.INTERVAL_HOUR * 3);
String[] selectionArgs = { "" + pastThreeHour, "" + currentTime };
Cursor cursor = contentResolver.query(uri, null, selection, selectionArgs, "date DESC");
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String number = cursor.getString(cursor.getColumnIndex("address")); // check for null
String date = cursor.getString(cursor.getColumnIndex("date")); // convert to date its long
String message_text = cursor.getString(cursor.getColumnIndex("body"));
String type = cursor.getString(cursor.getColumnIndex("type")); // check type and get names
// send email from here
sendSMSEmail(number, date, message_text, type);
}
}
cursor.close();
}
private void getCallLogData() {
Uri uri = Uri.parse("content://call_log/calls");
String[] projection = new String[] { Calls.TYPE, Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME, Calls.DURATION };
String selection = "date BETWEEN ? AND ? ";
long currentTime = System.currentTimeMillis();
long pastThreeHour = currentTime - (AlarmManager.INTERVAL_HOUR * 3);
String[] selectionArgs = { "" + pastThreeHour, "" + currentTime };
Cursor cursor = mContext.getContentResolver().query(uri, projection, selection, selectionArgs, "date DESC");
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String num = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
// convert long date to date
String date = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.DATE));
String name = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
String duration = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.DURATION));
int type = Integer.parseInt(cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.TYPE)));
String typeName = null;
switch (type) {
case 1:
typeName = "Incoming";
break;
case 2:
typeName = "Outgoing";
break;
case 3:
typeName = "Missed";
break;
}
sendCallEmail(num, date, name, duration, typeName);
}
}
}
private void sendCallEmail(String num, String date, String name, String duration, String typeName) {
// TODO Auto-generated method stub
}
private void sendSMSEmail(String number, String date, String message_text, String type) {
// TODO Auto-generated method stub
}
}
実際、これらの取得したデータを自分のメール ID に送信する方法がわかりません。メール ID は、ユーザーのみが提供する必要があります。メールを送るのを手伝ってください。前もって感謝します。