Sending an email through codename one

915 views
Skip to first unread message

Marko Vidalis

unread,
Sep 21, 2013, 11:17:59 AM9/21/13
to codenameone...@googlegroups.com
Hi all,

I have an app where a user fills a form in with information, and when clicking a button, this information is saved to storage. However, i'd also like the app to send the user an email notification when the button is pressed. Is there any way the email can be sent directly through the app? I've tried

Display.sendMessage(new String[]{findTxtAddress(c).getText()}, "Confirmation", mail);

however this opens a microsoft outlook window. This does not serve my purpose, i would like the email to be sent directly.

Thanks in advance

Marko

Chen Fishbein

unread,
Sep 21, 2013, 11:46:09 AM9/21/13
to codenameone...@googlegroups.com

Tiago Lopes

unread,
Nov 7, 2013, 10:15:03 AM11/7/13
to codenameone...@googlegroups.com
Hi guys,

I'm using that sendMessage method and I'm receiving the e-mail correctly but I'm having a problem. After my e-mail is sent, it should return to last form but my app is restarting and I don't know why. Is it normal or is it just me?

System.out.println("CAMERA");
d.dispose();
try {
  String value = Capture.capturePhoto(Display.getInstance().getDisplayWidth() / 2, -1);
  if(value != null) {
    Label image = new Label(Image.createImage(value));
    Message msg = new Message("");
    msg.setAttachment(value);
    showForm("MainMenu", null);
    Display.getInstance().sendMessage(new String[] {user.getEmailTo()}, "Image capture", msg);
  }
  else
  {
    System.out.println("User canceled.");
    genericDialog("Camera Capture Info", "User canceled capture.");
    showForm("MainMenu", null);
  }
} catch (Exception ex) {}

So Chen, if I got it right, if I have a pro account I can use that sendMessageViaCloud method on my app?

Chen Fishbein

unread,
Nov 7, 2013, 12:53:50 PM11/7/13
to codenameone...@googlegroups.com
yes, the sendMessageViaCloud is using the cloud server to send the e-mail which means the app won't open the email client.

Shai Almog

unread,
Nov 7, 2013, 2:01:19 PM11/7/13
to codenameone...@googlegroups.com
Since the mail app is an external app your app gets suspended (stop()) then start() is invoked again to indicate your app got control back.
Check that your lifecycle code can handle that behavior, the default code we generate should work just fine.

Tiago Lopes

unread,
Nov 7, 2013, 6:57:30 PM11/7/13
to codenameone...@googlegroups.com
So my objective is to remain on same place it stopped. Is possible to make it that way?
While I was searching about this, I got to this post. There Chen talks about init, start, stop and destroy method. I need to override start method so that my app can restore to a given form?

Can you show me an example so I can get how can I change it? :S

Tiago Lopes

unread,
Nov 7, 2013, 7:46:33 PM11/7/13
to codenameone...@googlegroups.com
Well, I am really wasting your time i guess.
I just found them on my main class. I don't know why I was looking on my StatemMachine.java as my class but ok. -.-"

Now I see what you guys tried to tell me. They are well defined, I think:

    public void start() {
        if(current != null){
            current.show();
            return;
        }
        new StateMachine("/theme");        
    }

    public void stop() {
        current = Display.getInstance().getCurrent();
    }

Any guess why aren't they working? I'll keep trying to solve this issue and post any update.

Thanks
Message has been deleted

Tiago Lopes

unread,
Nov 7, 2013, 11:43:35 PM11/7/13
to codenameone...@googlegroups.com
So some hours after other develepments, I tried to check what was on that "current" form data on start() and on stop() methods.

    public void start() {
        if(current != null){
            Dialog.show("START", "Starting your app on:\n"+current.getTitle(), "OK", null);
            current.show();
            return;
        }
        else
            Dialog.show("START", "Starting your app with no loaded form.", "OK", null);
        new StateMachine("/theme");        
    }

    public void stop() {
        current = Display.getInstance().getCurrent();
        Dialog.show("STOP", "Stopping your app on:\n"+current.getTitle(), "OK", null);
    }

With this config my app opens e-mail client selection popup, and then, after e-mail is sent there is no STOP dialog and application restarts, showing "Starting your app with no loaded form." dialog. :S
Shouldn't it be keeping current form when application is stopped and reloading it when app starts again?

Best regards,
Tiago

Shai Almog

unread,
Nov 8, 2013, 12:21:52 AM11/8/13
to codenameone...@googlegroups.com
Dialog.show() is problematic since its a blocking method. You are effectively stopping the codename one thread in place creating a deadlock and forcing android to kill the app.
Android/iOS will kill any app that takes background CPU power and isn't defined as a service.

Your lifecycle seems to be fine, do you have a background thread that takes up CPU?

Tiago Lopes

unread,
Nov 8, 2013, 12:28:21 AM11/8/13
to codenameone...@googlegroups.com
If I understood your answer I don't think so, at least I have not defined anything to do it.
Can that sendMessage call do that?

Shai Almog

unread,
Nov 8, 2013, 3:10:41 PM11/8/13
to codenameone...@googlegroups.com
Dialog.show() is blocking e.g.:
System.out.println("A");
Dialog.show("", "Hi", "OK", null);
System.out.println("This will print only after you clicked OK");

That's pretty cool normally!
However, stop() is invoked by the system trying to suspend your application!
So if Dialog.show() is invoked stop() will never return and your app will effectively freeze. Android OS will have no choice but to kill the app.

If you want to track the suspend/resume behavior you need to install a tool such as DDMS and track printouts in the console or use the cloud logging facilities available to pro subscribers.

Tiago Lopes

unread,
Nov 11, 2013, 8:04:19 AM11/11/13
to codenameone...@googlegroups.com
Hello,

Actually I've investigated what was really happening and I got to a conclusion.
If I have the keyboard closed when I send the email, my app returns to where it is supposed to and all occurs as planned, but if I have the keyboard open then the form loads as if the keyboard was there.

Is this easy to solve?

Shai Almog

unread,
Nov 11, 2013, 12:29:06 PM11/11/13
to codenameone...@googlegroups.com
This sounds like a bug. Do you have DDMS installed?
Can you reproduce this with DDMS open and see if you get an exception? If so can you paste its stack trace here?

Tiago Lopes

unread,
Nov 11, 2013, 12:44:30 PM11/11/13
to codenameone...@googlegroups.com
I have DDMS installed, but since emulator isn't using keyboard it all runs smooth. Running on emulator it pops up my thunderbird and keeps working. But I'll give it a try and I'll show you the result.

Thanks,
Tiago


2013/11/11 Shai Almog <shai....@gmail.com>
This sounds like a bug. Do you have DDMS installed?
Can you reproduce this with DDMS open and see if you get an exception? If so can you paste its stack trace here?

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/b_2jSpc9TpI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/d99b18e0-6d6f-4034-946c-209f20a5312a%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Tiago Lopes
Universidade do Minho
Engenharia de Comunicações

Shai Almog

unread,
Nov 11, 2013, 12:51:44 PM11/11/13
to codenameone...@googlegroups.com
DDMS is designed to connect to the device so you can see the output from there. Make sure you have the proper USB drivers installed.

Tiago Lopes

unread,
Nov 11, 2013, 1:29:11 PM11/11/13
to codenameone...@googlegroups.com
I runned it with DDMS open, and I got no exception. Want me to get some info from DDMS?

I sent 2 screenshoots from mobile, taken with DDMS:
1 - taken after I sent email, with keyboard closed
2 - taken after I sent email, with keyboard opened

Thanks


2013/11/11 Shai Almog <shai....@gmail.com>
DDMS is designed to connect to the device so you can see the output from there. Make sure you have the proper USB drivers installed.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/b_2jSpc9TpI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/groups/opt_out.
keyboard-closed.png
keyboard-not-closed.png

Shai Almog

unread,
Nov 12, 2013, 1:04:16 AM11/12/13
to codenameone...@googlegroups.com
Thanks, I made some fixes that would hopefully resolve this for the next update.
Reply all
Reply to author
Forward
0 new messages