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 7841559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:07:35+00:00 2026-06-02T16:07:35+00:00

I’m very new to android, and programming in general. I’ve got an email receiver

  • 0

I’m very new to android, and programming in general. I’ve got an email receiver using the K9 email client. I’m checking the email for proper formatting and taking the contents of the email and entering it into an SQLite database on the phone. The receiver is working properly. The problem is that when I send a properly formatted message, it makes 2 records from the first email. If I send another message without deleting the first one, it makes 4 records of the second. The third makes 6 records, etc. I know there is probably something obvious that I’m missing but I can’t find the problem.

Here is the code:

    public class EmailReceiver extends BroadcastReceiver{
private JobsData jobs;
public static final Uri k9uri = Uri.parse("content://com.fsck.k9.messageprovider/inbox_messages/");
static String[] messages_projection = new String[] {"subject", "preview", "unread"};


@Override
public void onReceive(Context context, Intent intent) {
    try {
        Context mContext = context;
        Cursor curSt = mContext.getContentResolver().query(k9uri, messages_projection, "unread='true'", null, null);
        curSt.moveToFirst();
        String preview = null;
        String subject = null;
        jobs = new JobsData(context);
        int i = 0;
        while (!curSt.isAfterLast()) {
            subject = curSt.getString(0);
            boolean test = subject.startsWith("JOB# ");
            if (test) {
                boolean check = true;
                try {
                    for (int k = 5; k < subject.length(); k++) {
                        if (!Character.isDigit(subject.charAt(k))) {
                            check = false;
                            break;
                        }
                    }
                } catch (Exception e) {
                } finally {
                }

                if (check) {
                    preview = curSt.getString(1);
                    compareDb(subject.substring(7), preview, context);
                }

            }
            curSt.moveToNext();
        }
        curSt.close();
    } catch (Exception e) {
        Toast toast = Toast.makeText(context, e.toString(), Toast.LENGTH_LONG);
        toast.show();
    }

    if (emails != null) {

     }
}


private void compareDb (String jobNo, String preview, Context context) {
    try {
    String[] dbJobs = new String[] {"JobNo"};
    SQLiteDatabase db = jobs.getReadableDatabase();
    Cursor dbCur = db.query(tableName, dbJobs, null, null, null, null, null);
    dbCur.moveToFirst();
    while (!dbCur.isAfterLast()) {
        if (!jobNo.equals(dbCur.getString(0))) {
            jobExtractor(preview, jobNo, context);
        }
        dbCur.moveToNext();
    }
    dbCur.close();
    } catch (Exception e){
        Toast toast = Toast.makeText(context, e.toString(), Toast.LENGTH_LONG);
        toast.show();

    }
}

private void addJobs(Job job){
    SQLiteDatabase db = jobs.getWritableDatabase();
    ContentValues values = new ContentValues();
        values.put(custName, job.getCustName());
        values.put(jobNumber, job.getJobNumber());
        values.put(jobType, job.getJobType());
        values.put(address, job.getAddress());
        values.put(zip, job.getZip());
        values.put(contact, job.getContact());
        values.put(contactNumber, job.getContactNumber());
        values.put(problem, job.getProblem());

    db.insertOrThrow(tableName, null, values);
    db.close();

}

The “jobextractor” method works fine so I didn’t include it. If someone can please help me I would appreciate it.

Thanks

Just a side note. I also want it to only look at unread email but that’s not working either. Not a major problem at this point but if you have an answer to that I would be very grateful.

  • 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-06-02T16:07:36+00:00Added an answer on June 2, 2026 at 4:07 pm

    I foundthe problem.

    while (!dbCur.isAfterLast()) { 
        if (!jobNo.equals(dbCur.getString(0))) { 
            jobExtractor(preview, jobNo, context); 
        } 
        dbCur.moveToNext(); 
    }
    

    The problem was here. I was checking to see if the job number matched existing records in the database. It went through each record in the table and added a new job for every record that didn’t match. I replaced the jobExctractor line with a boolean check and if the check returned true after the loop I didn’t add the job.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.