George
George

Reputation: 19

Export strings to email body

I have searched and I only found a similar question that was unanswered. I have a final report made of answers that have been input throughout the app. Now I've reached the end and I want to, basically, export the report to the email body.

package com.toc.maintenancereport;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Report extends Activity {
Button sendmail;

TextView elec1out, elec2out, elec3out, gasout, waterout, item1out,
        item2out, item3out, item4out, item5out, item6out, glsout, golfout,
        candlesout, gu10out, mr16out, g4capsout, fridgeout, cookhoodout,
        lamp1out, lamp2out, lamp3out, postout, cleanout, ironout,
        hairdryerout, hooverout, binsout, roofout, garageout, spaceout,
        outsideout, orderout, siliconeout, handlesout, furnitureout,
        wallsout, curtainsout, drawsout, itemsout, showerout, holesout,
        leaksout, tapsout, toiletsout, radout, thermoout, heatingout,
        wtanksout, hwaterout, boilerout, ovenout, clocksout, bulbsout,
        name, kettleout, tvout, fblanket, phoneout, fdoor, salarm, fescape,
        windowsout, consumerout, callout, internetout, issuesout;

String reportemail, elec1, elec2, elec3, gas, water, stockitem1,
        stockitem2, stockitem3, stockitem4, stockitem5, stockitem6,
        priceitem1, priceitem2, priceitem3, priceitem4, priceitem5,
        priceitem6, item1, item2, item3, item4, item5, item6, gls, golf,
        candles, gu10, mr16, g4caps, fridge, cookhood, lamp1, lamp2, lamp3,
        lamp1price, lamp2price, lamp3price, post, clean, iron, hairdryer,
        hoover, bins, roof, garage, space, outside, order, silicone,
        handles, furniture, walls, curtains, draws, items, shower, holes,
        leaks, taps, toilets, rad, thermo, heating, wtanks, hwater, boiler,
        oven, clocks, name2, internet, phone, kettle, tv, windows,
        consumer, firedoor, smokealarm, fireescape, fireblanket, property,
        date2, dateend, bulbs, issues = "";

String callt1 = "";
String callt2 = "";
String callt3 = "";
String callt4 = "";
String callt5 = "";
String callt6 = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.report);
    SharedPreferences dados = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());
    name = (TextView) findViewById(R.id.namereport);
    fblanket = (TextView) findViewById(R.id.whyfireblanket);
    fescape = (TextView) findViewById(R.id.whyfireescape);
    salarm = (TextView) findViewById(R.id.whysmokealarme);
    fdoor = (TextView) findViewById(R.id.whyfiredoor);
    callout = (TextView) findViewById(R.id.callouttv);
    consumerout = (TextView) findViewById(R.id.consumertv);
    windowsout = (TextView) findViewById(R.id.windowstv);
    tvout = (TextView) findViewById(R.id.tvtv);
    kettleout = (TextView) findViewById(R.id.kettletv);
    phoneout = (TextView) findViewById(R.id.phonetv);
    internetout = (TextView) findViewById(R.id.internettv);
    bulbsout = (TextView) findViewById(R.id.bulbstv);
    clocksout = (TextView) findViewById(R.id.clockstv);
    ovenout = (TextView) findViewById(R.id.oventv);
    boilerout = (TextView) findViewById(R.id.boilertv);
    hwaterout = (TextView) findViewById(R.id.hwatertv);
    wtanksout = (TextView) findViewById(R.id.wtankstv);
    heatingout = (TextView) findViewById(R.id.heatingtv);
    thermoout = (TextView) findViewById(R.id.thermotv);
    radout = (TextView) findViewById(R.id.radtv);
    toiletsout = (TextView) findViewById(R.id.toiletstv);
    tapsout = (TextView) findViewById(R.id.tapstv);
    leaksout = (TextView) findViewById(R.id.leakstv);
    holesout = (TextView) findViewById(R.id.holestv);
    showerout = (TextView) findViewById(R.id.showertv);
    itemsout = (TextView) findViewById(R.id.itemstv);
    drawsout = (TextView) findViewById(R.id.drawstv);
    curtainsout = (TextView) findViewById(R.id.curtainstv);
    wallsout = (TextView) findViewById(R.id.wallstv);
    furnitureout = (TextView) findViewById(R.id.furnituretv);
    handlesout = (TextView) findViewById(R.id.handlestv);
    siliconeout = (TextView) findViewById(R.id.siliconetv);
    orderout = (TextView) findViewById(R.id.ordertv);
    outsideout = (TextView) findViewById(R.id.outsidetv);
    spaceout = (TextView) findViewById(R.id.spacetv);
    garageout = (TextView) findViewById(R.id.garagetv);
    roofout = (TextView) findViewById(R.id.rooftv);
    binsout = (TextView) findViewById(R.id.binstv);
    hooverout = (TextView) findViewById(R.id.hoovertv);
    hairdryerout = (TextView) findViewById(R.id.hairdryertv);
    ironout = (TextView) findViewById(R.id.irontv);
    cleanout = (TextView) findViewById(R.id.cleantv);
    postout = (TextView) findViewById(R.id.posttv);
    glsout = (TextView) findViewById(R.id.glstv);
    golfout = (TextView) findViewById(R.id.golftv);
    candlesout = (TextView) findViewById(R.id.candlestv);
    gu10out = (TextView) findViewById(R.id.gu10tv);
    mr16out = (TextView) findViewById(R.id.mr16tv);
    g4capsout = (TextView) findViewById(R.id.g4capstv);
    fridgeout = (TextView) findViewById(R.id.fridgetv);
    cookhoodout = (TextView) findViewById(R.id.choodtv);
    lamp1out = (TextView) findViewById(R.id.lamp1tv);
    lamp2out = (TextView) findViewById(R.id.lamp2tv);
    lamp3out = (TextView) findViewById(R.id.lamp3tv);
    item1out = (TextView) findViewById(R.id.item1tv);
    item2out = (TextView) findViewById(R.id.item2tv);
    item3out = (TextView) findViewById(R.id.item3tv);
    item4out = (TextView) findViewById(R.id.item4tv);
    item5out = (TextView) findViewById(R.id.item5tv);
    item6out = (TextView) findViewById(R.id.item6tv);
    elec1out = (TextView) findViewById(R.id.meterelec1tv);
    elec2out = (TextView) findViewById(R.id.meterelec2tv);
    elec3out = (TextView) findViewById(R.id.meterelec3tv);
    gasout = (TextView) findViewById(R.id.metergastv);
    waterout = (TextView) findViewById(R.id.meterwatertv);
    issuesout = (TextView) findViewById(R.id.issuestv);
    sendmail=(Button)findViewById(R.id.bdonereport);

    name2 = dados.getString("Nome", "Nome");
    date2 = dados.getString("Date", "dd/MMM/yyyy");
    dateend = dados.getString("enddate", "dd/MMM/yyyy");

    property = dados.getString("Property", "Property");
    callt1 = dados.getString("Job1", "");
    callt2 = dados.getString("Job2", "");
    callt3 = dados.getString("Job3", "");
    callt4 = dados.getString("Job4", "");
    callt5 = dados.getString("Job5", "");
    callt6 = dados.getString("Job6", "");
    name.setText("Name: " + name2 + ". " + "\nTime started: " + date2
            + "\nTime ended: " + dateend + "\nProperty: " + property);

    fireblanket = dados.getString("Whyfireblanket", "Not Checked");
    fblanket.setText("*Fire Blanket: " + fireblanket);
    fireescape = dados.getString("Whyfireescape", "Not Checked");
    fescape.setText("*Fire Escape Intructions on Front door and all escape routes clear: "
            + fireescape);
    smokealarm = dados.getString("Whysmokealarm", "Not Checked");
    salarm.setText("*Smoke alarms are tested and left in working order: "
            + smokealarm);
    firedoor = dados.getString("Whyfiredoor", "Not Checked");
    fdoor.setText("*Fire doors are closing properly and are not blocked: "
            + firedoor);
    consumer = dados.getString("Whyconsumer", "Not Checked");
    consumerout
            .setText("*The consumer unit is OK and everything is working: "
                    + consumer);
    windows = dados.getString("Whywindows", "Not Checked");
    windowsout
            .setText("*Are the windows opening correctly and in good condition? Are keys in place: "
                    + windows);
    tv = dados.getString("Whytv", "Not Checked");
    tvout.setText("*Are the TV,DVD player and remotes all working: " + tv);
    kettle = dados.getString("Whykettle", "Not Checked");
    kettleout.setText("*Kettle,Toaster and Microwave all working: "
            + kettle);
    phone = dados.getString("Whyphone", "Not Checked");
    phoneout.setText("*Phone has a dial tone and is barred for outgoing calls: "
            + phone);
    internet = dados.getString("Whyinternet", "Not Checked");
    internetout
            .setText("*Is the Internet working with the settings written on the top: "
                    + internet);
    bulbs = dados.getString("Whybulbs", "Not Checked");
    bulbsout.setText("*Are ALL the bulbs working: " + bulbs);
    clocks = dados.getString("Whyclocks", "Not Checked");
    clocksout.setText("*Are ALL the clocks set to the correct time: "
            + clocks);
    oven = dados.getString("Whyoven", "Not Checked");
    ovenout.setText("*Is the oven working and the time set: " + oven);
    boiler = dados.getString("Whyboiler", "Not Checked");
    boilerout.setText("*Is the pressure on the boiler correct: " + boiler);
    hwater = dados.getString("Whyhwater", "Not Checked");
    hwaterout
            .setText("*Is the hot water working and at a good temperature: "
                    + hwater);
    wtanks = dados.getString("Whywtanks", "Not Checked");
    wtanksout.setText("*Are the water tanks full: " + wtanks);
    heating = dados.getString("Whyheating", "Not Checked");
    heatingout.setText("*Is the Heating working in every room: " + heating);
    thermo = dados.getString("Whythermo", "Not Checked");
    thermoout
            .setText("*Is the thermostat set to 18° (winter and if a guest is moving in) or off(summer or no guest): "
                    + thermo);
    rad = dados.getString("Whyrad", "Not Checked");
    radout.setText("*Are the rad controls correct?: " + rad);
    toilets = dados.getString("Whytoilets", "Not Checked");
    toiletsout.setText("*Are the toilets flushing correctly: " + toilets);
    taps = dados.getString("Whytaps", "Not Checked");
    tapsout.setText("*Are the tap washers/o-rings OK: " + taps);
    leaks = dados.getString("Whyleaks", "Not Checked");
    leaksout.setText("*Are there any leaks(under the sinks, behind the toilets, around the showers, etc.): "
            + leaks);
    holes = dados.getString("Whyholes", "Not Checked");
    holesout.setText("*Are all plug holes draining well: " + holes);
    shower = dados.getString("Whyshower", "Not Checked");
    showerout
            .setText("*Are all showers working well, no leaks and shower heads in good order: "
                    + shower);
    items = dados.getString("Whyitems", "Not Checked");
    itemsout.setText("*Are there any items in the property that should not be there: "
            + items);
    draws = dados.getString("Whydraws", "Not Checked");
    drawsout.setText("*Have all the draws and cupboards been opened to make sure they are OK: "
            + draws);
    curtains = dados.getString("Whycurtains", "Not Checked");
    curtainsout
            .setText("*Are the curtains and blinds opening and closing correctly and fixed well: "
                    + curtains);
    walls = dados.getString("Whywalls", "Not Checked");
    wallsout.setText("*Are the carpets, upholstry and walls in good condition: "
            + walls);
    furniture = dados.getString("Whyfurniture", "Not Checked");
    furnitureout.setText("*Is the furniture all in good order: "
            + furniture);
    handles = dados.getString("Whyhandles", "Not Checked");
    handlesout
            .setText("*Are the door handles and locks working and not loose: "
                    + handles);
    silicone = dados.getString("Whysilicone", "Not Checked");
    siliconeout
            .setText("*Is the silicone in the bathrooms and kitchen in good order: "
                    + silicone);
    order = dados.getString("Whyorder", "Not Checked");
    orderout.setText("*Is the furniture positioned correctly: " + order);
    outside = dados.getString("Whyoutside", "Not Checked");
    outsideout
            .setText("*Is the outside of the property clean and in order: "
                    + outside);
    space = dados.getString("Whyspace", "Not Checked");
    spaceout.setText("*Is the parking space empty and clearly marked: "
            + space);
    garage = dados.getString("Whygarage", "Not Checked");
    garageout.setText("*Is the garage clean and clear: " + garage);
    roof = dados.getString("Whyroof", "Not Checked");
    roofout.setText("*Are the gutters clear, roof OK, Brickwork OK, Window seals OK: "
            + roof);
    bins = dados.getString("Whybins", "Not Checked");
    binsout.setText("*Are the bins are empty and clear: " + bins);
    hoover = dados.getString("Whyhoover", "Not Checked");
    hooverout.setText("*Hoover working and empty: " + hoover);
    hairdryer = dados.getString("Whyhairdryer", "Not Checked");
    hairdryerout.setText("*Hairdryer working: " + hairdryer);
    iron = dados.getString("Whyiron", "Not Checked");
    ironout.setText("*Iron working: " + iron);
    clean = dados.getString("Whyclean", "Not Checked");
    cleanout.setText("*Are the windows clean outside: " + clean);
    post = dados.getString("Whypost", "Not Checked");
    postout.setText("*Collected all post from the property and postbox: "
            + post);
    gls = dados.getString("GLS", "0");
    glsout.setText("*GLS: " + gls);
    golf = dados.getString("Golf", "0");
    golfout.setText("*Golf: " + golf);
    candles = dados.getString("Candles", "0");
    candlesout.setText("*Candles: " + candles);
    gu10 = dados.getString("GU-10", "0");
    gu10out.setText("*GU-10: " + gu10);
    mr16 = dados.getString("MR-16", "0");
    mr16out.setText("*MR-16: " + mr16);
    g4caps = dados.getString("G4-Caps", "0");
    g4capsout.setText("*G4-Caps: " + g4caps);
    fridge = dados.getString("Fridge", "0");
    fridgeout.setText("*Fridge: " + fridge);
    cookhood = dados.getString("Cooker_Hood", "0");
    cookhoodout.setText("*Cooker Hood: " + cookhood);
    lamp1 = dados.getString("lamp1", "0");
    lamp1price = dados.getString("lamp1price", "0");
    lamp1out.setText("*Other lamp: " + lamp1 + ". Cost " + lamp1price + "£");
    lamp2 = dados.getString("lamp2", "0");
    lamp2price = dados.getString("lamp2price", "0");
    lamp2out.setText("*Other lamp: " + lamp2 + ". Cost " + lamp2price + "£");
    lamp3 = dados.getString("lamp3", "0");
    lamp3price = dados.getString("lamp3price", "0");
    lamp3out.setText("*Other lamp: " + lamp3 + ". Cost " + lamp3price + "£");
    item1 = dados.getString("item1", "");
    priceitem1 = dados.getString("price1", "");
    stockitem1 = dados.getString("stock1", "");
    item1out.setText("*Item: " + item1 + ". Price: " + priceitem1
            + "£. Stock:" + stockitem1 + "£.");
    item2 = dados.getString("item2", "");
    priceitem2 = dados.getString("price2", "");
    stockitem2 = dados.getString("stock2", "");
    item2out.setText("*Item: " + item2 + ". Price: " + priceitem2
            + "£. Stock:" + stockitem2 + "£.");
    item3 = dados.getString("item3", "");
    priceitem3 = dados.getString("price3", "");
    stockitem3 = dados.getString("stock3", "");
    item3out.setText("*Item: " + item3 + ". Price: " + priceitem3
            + "£. Stock:" + stockitem3 + "£.");
    item4 = dados.getString("item4", "");
    priceitem4 = dados.getString("price4", "");
    stockitem4 = dados.getString("stock4", "");
    item4out.setText("*Item: " + item4 + ". Price: " + priceitem4
            + "£. Stock:" + stockitem4 + "£.");
    item5 = dados.getString("item5", "");
    priceitem5 = dados.getString("price5", "");
    stockitem5 = dados.getString("stock5", "");
    item5out.setText("*Item: " + item5 + ". Price: " + priceitem5
            + "£. Stock:" + stockitem5 + "£.");
    item6 = dados.getString("item6", "");
    priceitem6 = dados.getString("price6", "");
    stockitem6 = dados.getString("stock6", "");
    item6out.setText("*Item: " + item6 + ". Price: " + priceitem6
            + "£. Stock:" + stockitem6 + "£.");
    elec1 = dados.getString("elec1", "0");
    elec1out.setText("*Elec1: " + elec1);
    elec2 = dados.getString("elec2", "0");
    elec2out.setText("*Elec2: " + elec2);
    elec3 = dados.getString("elec3", "0");
    elec3out.setText("*Elec3: " + elec3);
    gas = dados.getString("gas", "0");
    gasout.setText("*Gas: " + gas);
    water = dados.getString("water", "0");
    waterout.setText("*Water: " + water);
    issues = dados.getString("issues", "none");
    issuesout.setText("*Side note: " + issues);

    if (callt1.equals("") && callt2.equals("") && callt3.equals("")
            && callt4.equals("") && callt5.equals("") && callt6.equals("")) {
        callout.setText("No Jobs done.");
    } else if (!callt1.equals("") && !callt2.equals("")
            && !callt3.equals("") && !callt4.equals("")
            && !callt5.equals("") && callt6.equals("")) {
        callout.setText("Jobs done:\n1." + callt1 + "\n2." + callt2
                + "\n3." + callt3 + "\n4." + callt4 + "\n5." + callt5);
    } else if (!callt1.equals("") && !callt2.equals("")
            && !callt3.equals("") && !callt4.equals("")
            && callt5.equals("") && callt6.equals("")) {
        callout.setText("Jobs done:\n1." + callt1 + "\n2." + callt2
                + "\n3." + callt3 + "\n4." + callt4);
    } else if (!callt1.equals("") && !callt2.equals("")
            && !callt3.equals("") && callt4.equals("") && callt5.equals("")
            && callt6.equals("")) {
        callout.setText("Jobs done:\n1." + callt1 + "\n2." + callt2
                + "\n3." + callt3);
    } else if (!callt1.equals("") && !callt2.equals("")
            && callt3.equals("") && callt4.equals("") && callt5.equals("")
            && callt6.equals("")) {
        callout.setText("Jobs done:\n1." + callt1 + "\n2." + callt2);
    } else if (!callt1.equals("") && callt2.equals("") && callt3.equals("")
            && callt4.equals("") && callt5.equals("") && callt6.equals("")) {
        callout.setText("Jobs done:\n1." + callt1);
    }

    else {
        callout.setText("Jobs done:\n1." + callt1 + "\n2." + callt2
                + "\n3." + callt3 + "\n4." + callt4 + "\n5." + callt5
                + "\n6." + callt6);
        reportemail="funny";

    }
    sendmail.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sendmail = new Intent(Intent.ACTION_SEND);
            sendmail.setData(Uri.parse("mailto:"));
            sendmail.setType("text/html");
            sendmail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
            sendmail.putExtra(Intent.EXTRA_SUBJECT, "Report");


  //here is where my problem begins: I want to fill the body with the details above but I cannot find a way.
            sendmail.putExtra(Intent.EXTRA_TEXT   , );

                 startActivity(Intent.createChooser(sendmail, "Send mail..."));
                 finish();
                 Log.i("Finished sending email...", "");



        }

    });

}
}

Upvotes: 0

Views: 57

Answers (1)

Devarsh Desai
Devarsh Desai

Reputation: 6112

If you want to export information to an email and then send it, I would highly recommend using Mailgun. They've made it really straight forward for developers to send emails via the API they've exposed. They have really great documentation in their Quick Start Guide to help developers integrate their service pretty effortlessly.

Please let me know if you have any questions!

Upvotes: 1

Related Questions