Skip to content

Commit e9ae618

Browse files
authored
Update SMS, contacts, and email docs (#4057)
1 parent 4f78667 commit e9ae618

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

docs/developer-guide/Miscellaneous-Features.asciidoc

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ Most of the low level phone functionality is accessible in the https://www.coden
66

77
==== SMS
88

9-
Codename One supports sending SMS messages but not receiving them as this functionality isn't portable. You can send an SMS using:
9+
Codename One supports sending SMS messages but not receiving them as this functionality isn't portable. You can send an SMS using either the `Display` singleton or the static helper methods on `CN`. Both APIs throw `IOException`, which you should handle in case the native layer reports a failure:
1010

1111
[source,java]
1212
----
13-
Display.getInstance().setSMS("+999999999", "My SMS Message");
13+
try {
14+
Display.getInstance().sendSMS("+999999999", "My SMS Message");
15+
// Or: CN.sendSMS("+999999999", "My SMS Message");
16+
} catch(IOException err) {
17+
Log.e(err);
18+
Dialog.show("SMS Failed", "Unable to send the SMS", "OK", null);
19+
}
1420
----
1521

16-
Android/Blackberry support sending SMS's in the background without showing the user anything. iOS & Windows Phone just don't have that ability, the best they can offer is to launch the native SMS app with your message already in that app. Android supports that capability as well (launching the OS native SMS app).
22+
Android supports sending SMS messages in the background without any UI. iOS doesn't provide that ability, so the best it can offer is to launch the native SMS app with your message composed for the user to send. Android supports that interactive flow as well (launching the OS native SMS app).
1723

18-
The default `sendSMS` API ignores that difference and simply works interactively on iOS/Windows Phone while sending
19-
in the background for the other platforms.
24+
The default `sendSMS` API ignores that difference and simply works interactively on iOS while sending
25+
in the background for Android when the platform allows it.
2026

2127
The `getSMSSupport` API returns one of the following options:
2228

@@ -35,16 +41,21 @@ A typical use of this API would be something like this:
3541

3642
[source,java]
3743
----
38-
switch(Display.getInstance().getSMSSupport()) {
39-
case Display.SMS_NOT_SUPPORTED:
40-
return;
41-
case Display.SMS_SEAMLESS:
42-
showUIDialogToEditMessageData();
43-
Display.getInstance().sendSMS(phone, data);
44-
return;
45-
default:
46-
Display.getInstance().sendSMS(phone, data);
47-
return;
44+
try {
45+
switch(Display.getInstance().getSMSSupport()) {
46+
case Display.SMS_NOT_SUPPORTED:
47+
return;
48+
case Display.SMS_SEAMLESS:
49+
showUIDialogToEditMessageData();
50+
Display.getInstance().sendSMS(phone, data);
51+
return;
52+
default:
53+
Display.getInstance().sendSMS(phone, data);
54+
return;
55+
}
56+
} catch(IOException err) {
57+
Log.e(err);
58+
Dialog.show("SMS Failed", "Unable to send the SMS", "OK", null);
4859
}
4960
----
5061

@@ -85,19 +96,6 @@ Display.getInstance().sendMessage(new String[] {"[email protected]"}, "Subject o
8596

8697
NOTE: Some features such as attachments etc. don't work correctly in the simulator but should work on iOS/Android
8798

88-
The email messaging API has an additional ability within the https://www.codenameone.com/javadoc/com/codename1/messaging/Message.html[Message] class. The `sendMessageViaCloud`
89-
method allows you to use the Codename One cloud to send an email without end user interaction. This feature is available to pro users only since it makes use of the Codename One cloud:
90-
91-
[source,java]
92-
----
93-
Message m = new Message("<html><body>Check out <a href=\"https://www.codenameone.com/\">Codename One</a></body></html>");
94-
m.setMimeType(Message.MIME_HTML);
95-
96-
// notice that we provide a plain text alternative as well in the send method
97-
boolean success = m.sendMessageViaCloudSync("Codename One", "[email protected]", "Name Of User", "Message Subject",
98-
"Check out Codename One at https://www.codenameone.com/");
99-
----
100-
10199
=== Contacts API
102100

103101
The contacts API provides us with the means to query the phone’s address book, delete elements from it and create new entries into it. To get the platform specific list of contacts you can use
@@ -118,7 +116,7 @@ Here you can specify true only for the attributes that actually matter to you.
118116

119117
Another capability of the contacts API is the ability to extract all of the contacts very quickly. This isn't supported on all platforms but platforms such as Android can really get a boost from this API as extracting the contacts one by one is remarkably slow on Android.
120118

121-
You can check if a platform supports the extraction of all the contacts quickly thru `ContactsManager.isGetAllContactsFast()`.
119+
You can check if a platform supports the extraction of all the contacts quickly thru `ContactsManager.isAllContactsFast()`.
122120

123121
IMPORTANT: When retrieving all the contacts, notice that you should probably not retrieve all the data and should set some fields to false to perform a more efficient query
124122

@@ -129,7 +127,7 @@ You can then extract all the contacts using code that looks a bit like this, not
129127
Form hi = new Form("Contacts", new BoxLayout(BoxLayout.Y_AXIS));
130128
hi.add(new InfiniteProgress());
131129
Display.getInstance().scheduleBackgroundTask(() -> {
132-
Contact[] contacts = ContactsManager.getAllContacts(true, true, false, true, false, false);
130+
Contact[] contacts = ContactsManager.getContacts(true, true, false, true, false, false);
133131
Display.getInstance().callSerially(() -> {
134132
hi.removeAll();
135133
for(Contact c : contacts) {

0 commit comments

Comments
 (0)