This commit is contained in:
Jens 2021-09-16 22:50:34 +02:00
parent 074ac783a8
commit 94ce9bfffd
2 changed files with 42 additions and 8 deletions

View File

@ -10,10 +10,17 @@ import android.widget.Button;
import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends Activity
{
Button bRead;
final static int typeSMS = 0;
final static int typeMMS = 1;
final static int typeICS = 2;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
@ -27,29 +34,54 @@ public class MainActivity extends Activity
@Override
public void onClick(View v)
{
readMessage();
readMessages(typeICS);
}
});
}
void readMessage()
void readMessages(int messageType)
{
// public static final String INBOX = "content://sms/inbox";
// public static final String SENT = "content://sms/sent";
// public static final String DRAFT = "content://sms/draft";
Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
Uri path = null;
switch (messageType)
{
case typeSMS:
path = Uri.parse("content://sms/inbox");
break;
case typeMMS:
path = Uri.parse("content://mms/inbox");
break;
case typeICS:
path = Uri.parse("content://im/chat");
break;
default:
path = Uri.parse("content://sms/inbox");
break;
}
Cursor cursor = getContentResolver().query(path, null, null, null, null);
if (cursor.moveToFirst())
{
// must check the result to prevent exception
long messageCounter = 0;
do
{
String msgData;
for(int idx=0; idx<cursor.getColumnCount(); idx++)
messageCounter++;
String message = null;
Map<String,String> messageMap = new HashMap();
for(int i=0; i < cursor.getColumnCount(); i++)
{
msgData = " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
Log.i("message", msgData);
messageMap.put(cursor.getColumnName(i), cursor.getString(i));
message += cursor.getColumnName(i) + ": " + cursor.getString(i) + ", ";
// Log.i("message", msgData);
}
Log.i("Message", "Message nr. " + messageCounter + " " + message);
// use msgData
}
while (cursor.moveToNext());

View File

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:gravity="center_horizontal">
<Button
android:id="@+id/bRead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Read" />
</androidx.appcompat.widget.LinearLayoutCompat>