DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Build a Simple Chat Server With gRPC in .Net Core
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
  • Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Add a Text Message to a Messages Conversation in Android SDK

How to Add a Text Message to a Messages Conversation in Android SDK

Marcin Świerczyński user avatar by
Marcin Świerczyński
·
Jul. 25, 10 · Interview
Like (0)
Save
Tweet
Share
20.53K Views

Join the DZone community and get the full member experience.

Join For Free
Today I've published a new version of my AutoResponder Android application. The main feature in this release was quite simple: show auto-sent messages within standard messages conversation, just as if they were sent by hand. So, how do you do this in the Android SDK? Because it is a background operation, not visible to user, I've decided to build a Service to accomplish this task.
//imports

public class SentSmsLogger extends Service {

private static final String TELEPHON_NUMBER_FIELD_NAME = "address";
private static final String MESSAGE_BODY_FIELD_NAME = "body";
private static final Uri SENT_MSGS_CONTET_PROVIDER = Uri.parse("content://sms/sent");

@Override
public void onStart(Intent intent, int startId) {
addMessageToSentIfPossible(intent);
stopSelf();
}

private void addMessageToSentIfPossible(Intent intent) {
if (intent != null) {
String telNumber = intent.getStringExtra("telNumber");
String messageBody = intent.getStringExtra("messageBody");
if (telNumber != null && messageBody != null) {
addMessageToSent(telNumber, messageBody);
}
}
}

private void addMessageToSent(String telNumber, String messageBody) {
ContentValues sentSms = new ContentValues();
sentSms.put(TELEPHON_NUMBER_FIELD_NAME, telNumber);
sentSms.put(MESSAGE_BODY_FIELD_NAME, messageBody);

ContentResolver contentResolver = getContentResolver();
contentResolver.insert(SENT_MSGS_CONTET_PROVIDER, sentSms);
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

}

SentSmsLogger expects an Intent with receiver number and message body. Then it passes that information to proper ContentProvider. And this is the clue - it isn't well documented how to manage ContentProvider associated with messaging module. Google to the rescue ;) I've found information that relevant the ContentProvider has the URI content://sms/sent.

The next step was to find out the names of the fields that contain data about message body and its receiver. With the help of debugger, I've found them - it's body and address. I've put all of this in private constants at the top of class. That's all! Now we can use this data in a standard manner. Useful information about this can be found in the official documentation. Important note: due to compatibility issues, I've used Android SDK v. 1.5 here.

Software development kit Android SDK Android (robot) Conversations (software)

Opinions expressed by DZone contributors are their own.

Trending

  • Build a Simple Chat Server With gRPC in .Net Core
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
  • Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: