Difficulty Accessing SMS Data on Samsung Devices with Default Messagin

Hello Samsung Developer Community,

I am a developer of a personal finance management Android application that requires reading user SMS data to provide notifications about financial transactions. While my approach works seamlessly on all Android devices, I am facing a challenge specifically when trying to read SMS messages from the default Samsung messaging application.

Issue Description:

I have implemented the following code to query SMS messages using the ContentResolver. While the code effectively retrieves SMS messages from all devices, it fails to return messages when the Samsung default messaging app is used. However, it works as expected with the Google Messages application.

Here’s a snippet of my code that demonstrates how I query SMS data:

Explain

@Nullable
@Override
protected Cursor getCursor() {
    Cursor cursor = null;
    try {
        // Primary query to inbox URI
        cursor = querySmsInbox();

        // Fallback to querying all SMS if inbox query fails or is empty
        if (cursor == null || cursor.getCount() == 0) {
            cursor = queryAllSms();
        }
        if (cursor == null || cursor.getCount() == 0) {
            cursor = querySmsConversations();
        }
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
    }
    return cursor;
}

private Cursor querySmsInbox() {
    try {
        String where = getWhereClause();
        String[] whereArgs = getWhereArgs();
        return contentResolver.query(
                Uri.parse("content://sms/inbox"),
                new String[]{QuerySmsContentProvider.MESSAGE_COLUMN, QuerySmsContentProvider.DATE_COLUMN,
                        QuerySmsContentProvider.ADDRESS_COLUMN},
                where,
                whereArgs,
                null
        );
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        return null;
    }
}

  private Cursor queryAllSms() {
        try {
            String where = getWhereClause() + " AND type = ?";
            String[] whereArgs = {getWhereArgs()[0], "1"}; // Type 1 for inbox messages
            return contentResolver.query(
                    Uri.parse("content://sms"),
                    new String[]{QuerySmsContentProvider.MESSAGE_COLUMN, QuerySmsContentProvider.DATE_COLUMN,
                            QuerySmsContentProvider.ADDRESS_COLUMN},
                    where,
                    whereArgs,
                    null
            );
        } catch (Exception e) {
            FirebaseCrashlytics.getInstance().recordException(e);
            return null;
        }
    }

    private Cursor querySmsConversations() {
        try {
            String where = getWhereClause();
            String[] whereArgs = getWhereArgs();
            return contentResolver.query(
                    Uri.parse("content://sms/conversations"),
                    new String[]{QuerySmsContentProvider.MESSAGE_COLUMN, QuerySmsContentProvider.DATE_COLUMN,
                            QuerySmsContentProvider.ADDRESS_COLUMN},
                    where,
                    whereArgs,
                    null
            );
        } catch (Exception e) {
            FirebaseCrashlytics.getInstance().recordException(e);
            return null;
        }
    }

    private String[] getWhereArgs() {
        return new String[]{String.valueOf(lastSync)};
    }

    private String getWhereClause() {
        return QuerySmsContentProvider.DATE_COLUMN + " > ?";
    }

### Specifics of the Problem:

* **Environment**: The issue occurs only on devices with the Samsung default messaging app.
* **Functionality**: The queries run without errors but return no SMS data when using the Samsung messaging app.
* **Working**: The same code works correctly on every other device with either default apps or the Google Messages app.

### Request for Assistance:

I would appreciate any insights or advice from the community that might help troubleshoot this issue. Has anyone else experienced similar problems on Samsung devices? Are there any specific permissions or configurations that must be considered when interacting with SMS content on Samsung devices? Any assistance or direction to relevant resources would be greatly appreciated!

Thank you for your help!

Hello
Create a support request in the following channel.
Dev Support | Samsung Developer