diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a2ad74c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+# RCS Exporter
+
+I've been using the app SMS Backup & Restore for years. After getting a new phone and transferring the messages over I noticed some were missing.
+
+I tried to find out why this is happening - because of a "new" message type called RCS: https://en.wikipedia.org/wiki/Rich_Communication_Services
+
+Essentially those messages are stored in a separate database on the phone, hence not considered regular text messages.
+
+The above mentioned program is not able to export those messages (as of September 2021).
+
+I didn't want to reinvent the wheel - there are already enough backup/restore apps for SMS and MMS. Instead I just wanted to be able to export the RCS messages, too. Preferably it should be a format the SMS BR can then import.
+
+So if you're interested:
+1. Backup your SMS and MMS messages with another program.
+2. Import them on the target phone.
+3. Export the RCS using this app.
+4. Import those on the new phone as well.
+
+Remarks:
+- This program has only been tested with text messages. I don't know if images, etc. can be exported as well.
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 34322b4..9e28bf8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -11,6 +11,7 @@ android {
targetSdk 30
versionCode 1
versionName "1.0"
+ useLibrary 'org.apache.http.legacy'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fee8163..d71bf9b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -27,6 +27,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/de/server47/smsexport/MainActivity.java b/app/src/main/java/de/server47/smsexport/MainActivity.java
index c70fd69..e0f2cfd 100644
--- a/app/src/main/java/de/server47/smsexport/MainActivity.java
+++ b/app/src/main/java/de/server47/smsexport/MainActivity.java
@@ -1,29 +1,40 @@
package de.server47.smsexport;
import android.app.Activity;
+import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.Toast;
import androidx.annotation.Nullable;
+import androidx.documentfile.provider.DocumentFile;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends Activity
{
- Button bRead;
+ Button bRead, bWrite;
final static int typeSMS = 0;
final static int typeMMS = 1;
final static int typeICS = 2;
+ final static int requestCodeExport = 815;
+
+ String contentToWrite = "bla";
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
@@ -31,6 +42,7 @@ public class MainActivity extends Activity
setContentView(R.layout.main_activity);
bRead = (Button)findViewById(R.id.bRead);
+ bWrite = (Button)findViewById(R.id.bWrite);
bRead.setOnClickListener(new View.OnClickListener()
{
@@ -48,37 +60,118 @@ public class MainActivity extends Activity
export.append("backup_date=\"1631273111057\"");
export.append("type=\"full\">");
// 05.05.2001 19:15:00
- String pattern = "dd-MM-yyyy H:m:s";
+ 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(
- "";
- response.get(i).get()
+ ""
);
}
export.append("");
-
+ contentToWrite = export.toString();
}
}
});
+
+ bWrite.setOnClickListener(new View.OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
+ startActivityForResult(intent, requestCodeExport);
+ }
+ });
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data)
+ {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if(resultCode == RESULT_OK)
+ {
+ switch (requestCode)
+ {
+ case requestCodeExport:
+ if (resultCode == RESULT_OK)
+ {
+ Uri uriTree = data.getData();
+ exportFiles(uriTree, contentToWrite);
+ }
+ break;
+ }
+ }
+ }
+
+ void exportFiles(Uri uriTree, String content)
+ {
+ String fileName = "Message_export_" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + ".xml";
+
+ DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
+
+ // Clean up
+// for(DocumentFile file : directory.listFiles())
+// {
+// /*
+// On some few users' devices it seems this caused a crash because file.getName() was null.
+// The reason for that remains unknown, but we don't want the export to crash because of it.
+// */
+// if(!StringUtils.isEmpty(file.getName()))
+// {
+// if (file.getName().equals(XmlFileInterface.settingsFileName) && file.canWrite())
+// file.delete();
+// else if (file.getName().equals(prefsFileName) && file.canWrite())
+// file.delete();
+// }
+// }
+
+ DocumentFile exportFile = directory.createFile("text/xml", fileName);
+
+ if(exportFile.canWrite())
+ {
+ try
+ {
+ OutputStream out = getApplicationContext().getContentResolver().openOutputStream(exportFile.getUri());
+ out.write(content.getBytes());
+ out.close();
+
+ Toast.makeText(MainActivity.this, "Export complete.", Toast.LENGTH_LONG).show();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ Toast.makeText(MainActivity.this, "Error while writing file.", Toast.LENGTH_LONG).show();
+ }
+ }
+// else
+// Toast.makeText(MainActivity.this, getResources().getString(R.string.ConfigurationExportError), Toast.LENGTH_LONG).show();
}
List