This commit is contained in:
Jens 2021-09-17 23:05:11 +02:00
parent 94ce9bfffd
commit 57fe7ab08a

View File

@ -10,7 +10,10 @@ import android.widget.Button;
import androidx.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends Activity
@ -34,12 +37,51 @@ public class MainActivity extends Activity
@Override
public void onClick(View v)
{
readMessages(typeICS);
List<Map<String,String>> response = readMessages(typeICS);
if(response.size() > 0)
{
StringBuilder export = new StringBuilder();
export.append("<?xml-stylesheet type=\"text/xsl\" href=\"sms.xsl\"?>");
export.append("<smses count=\"" + String.valueOf(response.size()) + "\"");
export.append("backup_set=\"c6e0fda0-9bc0-48e2-893f-10ec95966e70\"");
export.append("backup_date=\"1631273111057\"");
export.append("type=\"full\">");
// 05.05.2001 19:15:00
String pattern = "dd-MM-yyyy H:m:s";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
for(int i = 0; i < response.size(); i++)
{
export.append(
"<sms protocol=\"0\"" +
"address=\"" + response.get(i).get("remote_uri").replace("tel:", "") + "\"" +
"date=\"" + response.get(i).get("date") + "\"" +
"type=\"1\"" +
"subject=\"null\"" +
"body=\"" + response.get(i).get("body") + "\"" +
"toa=\"null\"" +
"sc_toa=\"null\"" +
"service_center=\"null\"" +
"read=\"1\"" +
"status=\"-1\"" +
"locked=\"0\"" +
"date_sent=\"0\"" +
"sub_id=\"-1\"" +
"readable_date=\"" + 05.05.2001 19:15:00 + "\"" +
"contact_name=\"(Unknown)\"/>";
response.get(i).get()
);
}
export.append("</smses>");
}
}
});
}
void readMessages(int messageType)
List<Map<String,String>> readMessages(int messageType)
{
// public static final String INBOX = "content://sms/inbox";
// public static final String SENT = "content://sms/sent";
@ -63,6 +105,8 @@ public class MainActivity extends Activity
break;
}
List<Map<String,String>> returnList = new ArrayList<>();
Cursor cursor = getContentResolver().query(path, null, null, null, null);
if (cursor.moveToFirst())
@ -82,7 +126,7 @@ public class MainActivity extends Activity
}
Log.i("Message", "Message nr. " + messageCounter + " " + message);
// use msgData
returnList.add(messageMap);
}
while (cursor.moveToNext());
}
@ -91,5 +135,7 @@ public class MainActivity extends Activity
// empty box, no SMS
Log.i("message", "no messages");
}
return returnList;
}
}