Progress display
This commit is contained in:
parent
ed1445dd4e
commit
165df24f0c
10
README.md
10
README.md
@ -11,11 +11,13 @@ Unfortunately SMS BR is not able to export this kind of messages (as of Septembe
|
|||||||
I didn't want to reinvent the wheel - there are already enough backup/restore apps for SMS and MMS. Instead I just wanted to make an app that was able to export the RCS messages, too. Preferably it should be a format that SMS BR could then import.
|
I didn't want to reinvent the wheel - there are already enough backup/restore apps for SMS and MMS. Instead I just wanted to make an app that was able to export the RCS messages, too. Preferably it should be a format that SMS BR could then import.
|
||||||
|
|
||||||
## So if you're interested:
|
## So if you're interested:
|
||||||
1. Backup your SMS and MMS messages with another program.
|
1. Backup your SMS and MMS messages with another program, e.g. SMS BR
|
||||||
2. Import them on the target phone.
|
2. Import them on the target phone.
|
||||||
3. Export the RCS using this app.
|
3. Export the RCS messages using this app.
|
||||||
4. Import those on the new phone as well.
|
4. Import those on the new phone as well, e.g. with SMS BR.
|
||||||
|
|
||||||
## Remarks:
|
## Remarks:
|
||||||
- Technically the RCS will be converted to SMS messages.
|
- This program cannot IMport anything, just export.
|
||||||
|
- Technically the RCS messages will be converted to SMS messages.
|
||||||
- This program has only been tested with text messages. I don't know if images, etc. can be exported as well.
|
- This program has only been tested with text messages. I don't know if images, etc. can be exported as well.
|
||||||
|
- Because I don't see any real value in RCS messages over SMS, I deactivated advanced messaging in my SMS app. I encourage you to consider doing the same.
|
@ -65,6 +65,99 @@ public class MainActivity extends Activity
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AsyncTaskExport extends AsyncTask<Uri, Integer, Void>
|
||||||
|
{
|
||||||
|
String getExportString()
|
||||||
|
{
|
||||||
|
List<Map<String,String>> response;
|
||||||
|
|
||||||
|
if(rbSms.isChecked())
|
||||||
|
response = readMessages(typeSMS);
|
||||||
|
else if(rbMms.isChecked())
|
||||||
|
response = readMessages(typeMMS);
|
||||||
|
else
|
||||||
|
response = readMessages(typeRCS);
|
||||||
|
|
||||||
|
if(response.size() > 0)
|
||||||
|
{
|
||||||
|
messageCount = response.size();
|
||||||
|
|
||||||
|
publishProgress((int)Math.round(messageCount/response.size()));
|
||||||
|
|
||||||
|
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=\"" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + "\"");
|
||||||
|
export.append(" backup_date=\"" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + "\"");
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTimeInMillis(Long.parseLong(response.get(i).get("date")));
|
||||||
|
|
||||||
|
/*
|
||||||
|
type: 1 = inbound
|
||||||
|
type: 2 = outbound
|
||||||
|
*/
|
||||||
|
|
||||||
|
export.append("<sms protocol=\"0\"");
|
||||||
|
|
||||||
|
if(!StringUtils.isEmpty(response.get(i).get("remote_uri")))
|
||||||
|
export.append(" address=\"" + response.get(i).get("remote_uri").replace("tel:", "") + "\"");
|
||||||
|
else
|
||||||
|
export.append(" address=\"" + response.get(i).get("address") + "\"");
|
||||||
|
|
||||||
|
export.append(
|
||||||
|
" date=\"" + response.get(i).get("date") + "\"" +
|
||||||
|
" type=\"" + response.get(i).get("type") + "\"" +
|
||||||
|
" subject=\"null\"" +
|
||||||
|
" body=\"" + StringEscapeUtils.escapeXml11(response.get(i).get("body")).replace("\n", " ") + "\"" +
|
||||||
|
" toa=\"null\"" +
|
||||||
|
" sc_toa=\"null\"" +
|
||||||
|
" service_center=\"null\"" +
|
||||||
|
" read=\"1\"" +
|
||||||
|
" status=\"-1\"" +
|
||||||
|
" locked=\"0\"" +
|
||||||
|
" date_sent=\"" + response.get(i).get("date_sent") + "\"" +
|
||||||
|
" sub_id=\"-1\"" +
|
||||||
|
" readable_date=\"" + simpleDateFormat.format(cal.getTime()) + "\"" +
|
||||||
|
" contact_name=\"(Unknown)\"/>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export.append("</smses>");
|
||||||
|
return export.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Uri... uriTree)
|
||||||
|
{
|
||||||
|
String dataToWrite = getExportString();
|
||||||
|
if(!StringUtils.isEmpty(dataToWrite))
|
||||||
|
exportFiles(uriTree[0], dataToWrite);
|
||||||
|
else
|
||||||
|
Toast.makeText(MainActivity.this, "Error reading messages. Can\'t export.", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Integer... values)
|
||||||
|
{
|
||||||
|
super.onProgressUpdate(values);
|
||||||
|
pbStatus.setProgress(values[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
{
|
{
|
||||||
@ -77,107 +170,14 @@ public class MainActivity extends Activity
|
|||||||
case requestCodeExport:
|
case requestCodeExport:
|
||||||
if (resultCode == RESULT_OK)
|
if (resultCode == RESULT_OK)
|
||||||
{
|
{
|
||||||
AsyncTask<Void, Integer, Void> asyncTaskExport = new AsyncTask<Void, Integer, Void>()
|
AsyncTask<Uri,Integer,Void> exportTask = new AsyncTaskExport();
|
||||||
{
|
exportTask.execute(data.getData());
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... voids)
|
|
||||||
{
|
|
||||||
Uri uriTree = data.getData();
|
|
||||||
String dataToWrite = getExportString();
|
|
||||||
if(!StringUtils.isEmpty(dataToWrite))
|
|
||||||
exportFiles(uriTree, dataToWrite);
|
|
||||||
else
|
|
||||||
Toast.makeText(MainActivity.this, "Error reading messages. Can\'t export.", Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(Integer... values)
|
|
||||||
{
|
|
||||||
super.onProgressUpdate(values);
|
|
||||||
pbStatus.setProgress(values[0]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
asyncTaskExport.execute();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getExportString(AsyncTask<Void,Integer,Void> asyncTaskReference)
|
|
||||||
{
|
|
||||||
List<Map<String,String>> response;
|
|
||||||
|
|
||||||
if(rbSms.isChecked())
|
|
||||||
response = readMessages(typeSMS);
|
|
||||||
else if(rbMms.isChecked())
|
|
||||||
response = readMessages(typeMMS);
|
|
||||||
else
|
|
||||||
response = readMessages(typeRCS);
|
|
||||||
|
|
||||||
if(response.size() > 0)
|
|
||||||
{
|
|
||||||
messageCount = response.size();
|
|
||||||
|
|
||||||
asyncTaskReference.publishProgress((int)Math.round(messageCount/response.size()));
|
|
||||||
|
|
||||||
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=\"" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + "\"");
|
|
||||||
export.append(" backup_date=\"" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + "\"");
|
|
||||||
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++)
|
|
||||||
{
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTimeInMillis(Long.parseLong(response.get(i).get("date")));
|
|
||||||
|
|
||||||
/*
|
|
||||||
type: 1 = inbound
|
|
||||||
type: 2 = outbound
|
|
||||||
*/
|
|
||||||
|
|
||||||
export.append("<sms protocol=\"0\"");
|
|
||||||
|
|
||||||
if(!StringUtils.isEmpty(response.get(i).get("remote_uri")))
|
|
||||||
export.append(" address=\"" + response.get(i).get("remote_uri").replace("tel:", "") + "\"");
|
|
||||||
else
|
|
||||||
export.append(" address=\"" + response.get(i).get("address") + "\"");
|
|
||||||
|
|
||||||
export.append(
|
|
||||||
" date=\"" + response.get(i).get("date") + "\"" +
|
|
||||||
" type=\"" + response.get(i).get("type") + "\"" +
|
|
||||||
" subject=\"null\"" +
|
|
||||||
" body=\"" + StringEscapeUtils.escapeXml11(response.get(i).get("body")).replace("\n", " ") + "\"" +
|
|
||||||
" toa=\"null\"" +
|
|
||||||
" sc_toa=\"null\"" +
|
|
||||||
" service_center=\"null\"" +
|
|
||||||
" read=\"1\"" +
|
|
||||||
" status=\"-1\"" +
|
|
||||||
" locked=\"0\"" +
|
|
||||||
" date_sent=\"" + response.get(i).get("date_sent") + "\"" +
|
|
||||||
" sub_id=\"-1\"" +
|
|
||||||
" readable_date=\"" + simpleDateFormat.format(cal.getTime()) + "\"" +
|
|
||||||
" contact_name=\"(Unknown)\"/>"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export.append("</smses>");
|
|
||||||
return export.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void exportFiles(Uri uriTree, String content)
|
void exportFiles(Uri uriTree, String content)
|
||||||
{
|
{
|
||||||
String fileName = "Message_export_" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + ".xml";
|
String fileName = "Message_export_" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + ".xml";
|
||||||
|
Loading…
Reference in New Issue
Block a user