Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:25:15+00:00 2026-05-24T05:25:15+00:00

I am making an application and I need to sync the current sms messages

  • 0

I am making an application and I need to sync the current sms messages received/sent within a week to my web server. This is the code I have, but it gets all the SMS Messages:

 SharedPreferences settings = getSharedPreferences("MyPrefs", 0);
    boolean firstTime = settings.getBoolean("FirstTime", true);
    if (firstTime) {
        Uri allMessage = Uri.parse("content://sms/");
        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(allMessage, null, null, null, null);
        while  (c.moveToNext()) {
           String row = c.getString(1);
           //upload it all here
        }
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("FirstTime", false);
        editor.commit();
    }

Another question is, will it be a lot to handle if I send each message one by one? Should I like group them together, and make it into XML/JSON and encode it (base64 probably), then send it to my server? But I’m afraid it might go over the sending limit of HTTP POST params.

EDIT
I have figured out the solution, you need to use what the query gives you back, so the 5th column is the date for all the messages, so you use an if statement to only submit the messages that are within 1 week (604800 seconds).

Uri allMessage = Uri.parse("content://sms/");
        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(allMessage, null, null, null, null);
            while(c.moveToNext()){
                int date = Math.round(Integer.parseInt(c.getString(4))/1000);
                int time_now = Math.round(System.currentTimeMillis()/1000);
                int difference = time_now - date;
                    if(difference < 604800){
                        String phoneNumber = c.getString(2);
                    String message = c.getString(11);
                                    //this sms is within a week old.
                    }


            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:25:16+00:00Added an answer on May 24, 2026 at 5:25 am

    you need to use the selection criteria for this..

    Cursor c = cr.query(allMessage, null, "recievedDate between date('now') and SELECT date('now','start of week','-1 week',''); ", null, null);
    

    this would create a SQL query to fetch the correct daya.. you might want to tweak the selection criteria a bit..

    the selection criteria is basically a where clause in an sql query except for the where keyword.

    here is an article on SQLLite datetime function

    hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an application for 3d ball balancing game on j2me, I need
We are making an application with the details below. 1) Web/Desktop App on C#.Net
I am making an application where I need for a contentEditable div to be
I am working on making an application run on both Postgres and SQL Server.
I am making Map application and I have already able to call web service
I am making an application where I need to verify the syntax of each
I am making one application in which one webservices need to be called, is
I'm making an Android application where I need to slow down the audio being
I am making an Automator application and I need to replace some text based
I'm making a java application and I need to play audio. I'm playing mainly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.