Is it possible to know the state of application invoked in blackberry? For example, if we invoke blackberry email application after sending an email, can we know if the application has closed or still running and also where the email has been sent, the subject, the content, etc.? The code may be something like this:
try {
Message message = new Message();
Address address = new Address("email#yahoo.com", "Email");
Address[] addresses = {address};
message.addRecipients(RecipientType.TO, addresses);
message.setContent("Testing email from MyTabViewDemo application");
message.setSubject("Testing Email");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
log.debug(MyApp.GUID_LOG, "Send email action done!");
} catch (Exception e) {
Dialog.inform(e.toString());
}
and how about retrieving the state of other applications like phone, sms, camera?
Thank you.
You can view the visible applications by calling
ApplicationManager.getApplicationManager().getVisibleApplications();
That returns an array of application descriptors. From a descriptor, you can know the names and ids.
It is possible, however, that the messaging app is always on background and cannot be closed (I'm not 100% sure here)
But you can't know if a message has ben sent or not sending the mail like that.
Related
Any endpoint for sending messages to specific users in Teams via the Graph API?
(Edited because of clarity and added Custom-Requests)
You can send messages via Graph API to private users BUT there is a problem that you can't create a new chat between two users via the Graph API. This means that if you want to send a message from a user to a user, the chat must already exist. (Messages must first have been exchanged via the MSTeams client for a chat to exist)
So make sure that you have a open chat!
If so, have a look at this MSDoc (This document explains how you can list chats from a user):
https://learn.microsoft.com/en-us/graph/api/chat-list?view=graph-rest-beta&tabs=http
After you have all your chats listed, you can have a look at this MSDoc (This document explains how you can send a message to a user):
https://learn.microsoft.com/en-us/graph/api/chat-post-messages?view=graph-rest-beta&tabs=http
Pay attention to the permissions! For sending messages and listing chats there are only delegated permissions so far AND these calls are only available in BETA, so be carefull with it.
I can only provide you Java code for an example.
(For everything I do I use ScribeJava to get an Auth-Token)
For delegated permissions you need to have a "User-Auth-Token". That means you have to use a Password-Credential-Grant like this:
private void _initOAuth2Service()
{
oAuth2Service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.defaultScope(GRAPH_SCOPE)
.build(MicrosoftAzureActiveDirectory20Api.custom(tenantId));
//PASSWORD CREDENTIALS FLOW
try
{
oAuth2Token = oAuth2Service.getAccessTokenPasswordGrant(username, password);
}
catch (IOException e) { e.printStackTrace(); }
catch (InterruptedException e) { e.printStackTrace(); }
catch (ExecutionException e) { e.printStackTrace(); }
}
username and password are the credentials from the user you want to send a message (sender).
Initial situation
This is my TeamsClient:
ScribeJava
Get all open chats
("me" in the URL is the user from above (sender).)
private Response _executeGetRequest()
{
final OAuthRequest request = new OAuthRequest(Verb.GET, "https://graph.microsoft.com/beta/me/chats");
oAuth2Service.signRequest(oAuth2Token, request);
return oAuth2Service.execute(request);
}
The response I get from this request looks like this:
{"#odata.context":"https://graph.microsoft.com/beta/$metadata#chats","value":[{"id":"{PartOfTheID}_{firstHalfOfUserID}-e52a55572b49#unq.gbl.spaces","topic":null,"createdDateTime":"2020-04-25T09:22:19.86Z","lastUpdatedDateTime":"2020-04-25T09:22:20.46Z"},{"id":"{secondUserChatID}#unq.gbl.spaces","topic":null,"createdDateTime":"2020-03-27T08:19:29.257Z","lastUpdatedDateTime":"2020-03-27T08:19:30.255Z"}]}
You can see that I have two open chats and get two entries back from the request.
Get the right conversatonID
You have to know that the id can be split in three sections. {JustAPartOfTheId}_{userId}#{EndOfTheId}. The {userId} is the id from your chatpartner (recipient).
This is a GraphExplorer response which gives me all users and all informations about them.
Now you can see that the first ID:
"id":"{PartOfTheID}_{firstHalfOfUserID}-e52a55572b49#unq.gbl.spaces"
matches the UserID after the "_".
You can split the ID at the "_" filter and find the ID you need.
Send Message to user
Now you know the right Id and can send a new request for the message like this:
final OAuthRequest request = new OAuthRequest(Verb.POST, "https://graph.microsoft.com/beta/chats/{PartOfTheID}_{firstHalfOfUserID}-e52a55572b49#unq.gbl.spaces/messages");
oAuth2Service.signRequest(oAuth2Token, request);
request.addHeader("Accept", "application/json, text/plain, */*");
request.addHeader("Content-Type", "application/json");
request.setPayload("{\"body\":{\"content\":\" " + "Hi Hi Daniel Adu-Djan" + "\"}}");
oAuth2Service.execute(request);
GraphAPI-Custom-Requests
In the Graph-SDK is no opportunity to use the beta endpoint except for Custom-Requests. (For these requests I also use ScribeJava to get an Auth-Token)
Set the BETA-Endpoint
When you want to use the BETA-Endpoint you have to use the setEndpoint() function like this:
IGraphServiceClient graphUserClient = _initGraphServiceUserClient();
//Set Beta-Endpoint
graphUserClient.setServiceRoot("https://graph.microsoft.com/beta");
Get all chats
try
{
JsonObject allChats = graphUserClient.customRequest("/me/chats").buildRequest().get();
}
catch(ClientException ex) { ex.printStacktrace(); }
Same response like above
Same situation with the userId => split and filter
Send message
IGraphServiceClient graphUserClient = _initGraphServiceUserClient();
//Set Beta-Endpoint again
graphUserClient.setServiceRoot("https://graph.microsoft.com/beta");
try
{
JsonObject allChats = graphUserClient.customRequest("/chats/{PartOfTheID}_{firstHalfOfUserID}-e52a55572b49#unq.gbl.spaces/messages").buildRequest().post({yourMessageAsJsonObject});
}
catch(ClientException ex) { ex.printStacktrace();
}
Here is a little GIF where you can see that I didn't type anything. I just started my little application and it sends messages automatically.
I hope this helps you. Feel free to comment if you don't understand something! :)
Best regards!
As of now, We do not have any endpoint to send messages to specific users via Graph API.
You may submit/vote a feature request in the UserVoice or just wait for the update from the Product Team.
You can vote for a below feature requests which are already created. All you have to do is enter your email ID and vote.
https://microsoftteams.uservoice.com/forums/555103-public/suggestions/40642198-create-new-1-1-chat-using-graph-api
https://microsoftteams.uservoice.com/forums/555103-public/suggestions/39139705-is-there-any-way-to-generate-chat-id-by-using-grap
Update:
Please find below one more user voice created for the same in Microsoft Graph user voices and vote for it.
https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/37802836-add-support-for-creating-chat-messages-on-the-user
I have setup a webhook and everything is working properly, however iam used to using a long number where STOP is handled automatically, but now I have a short code where we have to handle STOP ourselves. This isnt an issue on sending a message as I can check with my 'blacklist' numbers before sending the message. My question is in the Reply webhook, what is the best way or standard way to NOT send the reply message.
Below is twilios sample code (i added the comment where i would check if they are black listed)
public class SmsController : TwilioController
{
public TwiMLResult Index(SmsRequest incomingMessage)
{
var messagingResponse = new MessagingResponse();
// check for phone number in blacklist to NOT SEND
messagingResponse.Message("The copy cat says: " +
incomingMessage.Body);
return TwiML(messagingResponse);
}
}
If the number is blacklisted and i dont want to send the reply how do I "gracefully" not reply to them as this example takes a TwiMLResult and message response. Do i just set the message to an empty string ? do I return null? Any thoughts ? Thank you !
Is it possible to send an automatically generated email using my own email address to another email address of mine by clicking a button?
I tried to use MFMailComposeViewController but another view appeared. Can I do it without this view?
You can do it only by creating own server-side mailer. On button clicking you have to send request with all needed data (email address, body, subject, etc) and server will send mail.
If You want send directly from app - MFMailComposeViewController is the only LEGAL way
By default in iOS you can only use the MFMailComposeViewController, which uses the user's mail account. Therefore you cannot send fully automated mail messages (the user allways has to confirm/cancel).
libMailCore is a great iOS framework which allows you to generate and send mails without any user interferance. In that case you'll be using your own server/credentials (thus not the user mail account). There are apps in the App Store using mailcore, so i would guess it's legit.
Yes there is a way using Swift-SMTP.
Send email
Create a Mail object and use your SMTP handle to send it. To set the sender and receiver of an email, use the User struct:
let drLight = Mail.User(name: "Dr. Light", email: "drlight#gmail.com")
let megaman = Mail.User(name: "Megaman", email: "megaman#gmail.com")
let mail = Mail(
from: drLight,
to: [megaman],
subject: "Humans and robots living together in harmony and equality.",
text: "That was my ultimate wish."
)
smtp.send(mail) { (error) in
if let error = error {
print(error)
}
}
I have the following code in my app which listens and increments the counter when an sms is sent.
SendListener smsListener = new net.rim.blackberry.api.sms.SendListener() {
public boolean sendMessage(Message message) {
++smsCount;
return true;
}
};
However, for some reason the sendMessage method is called multiple times (usually this is 3 times) when only a single sms is send (even when the sms message is very short).
Why is this ? Is there a workaround for this problem ?
I didn't find mention about this issue on bb dev forum. As Emmanuel suggested you probably register listener several times. Please review this thread:
http://supportforums.blackberry.com/t5/Java-Development/sendListener-sms-and-folder-listner-invalk-multiple-times/m-p/1978915/highlight/true#M211297
I am building an application where I need the option to share via email and SMS.
I have done the share via Email, where when the user selects the image, the url is passed as the content of the email. But while sharing via SMS, I can't do something like setContent as I did for email and fetch the url in the SMS directly, instead of user typing the address manually.
I am using Message class in email and MessageConnection class for SMS, as shown in the blackberry community example.
The Message object you receive when calling MessageConnection.newMessage(TEXT_MESSAGE) is actually a TextMessage object (or a BinaryMessage object with BINARY_MESSAGE).
If you cast the received object to the proper class (TextMessage or BinaryMessage), you should be able to use its setPayloadText(String data) (or setPayloadData(byte[] data) for a BinaryMessage) to enter a value in the message before sending it.
Your code should look like this:
Message msg = myMessageConnection.newMessage(TEXT_MESSAGE, /* address */);
TextMessage txtMsg = (TextMessage)msg;
txtMsg.setPayloadText(/* Text to send */);
myMessageConnection.send(msg);
When you send an email, you can set the body of it and send it to the user from the Email native application. You cant do taht for SMSs. I worked on that issue and for BB Torch I was able to set the text of the SMS message but for other devices that was impossible. I always obtain an empty text message!!
So y suggestion to you is using the following code wich will send the SMS to a number without the interference of the user
MessageConnection conn = (MessageConnection) Connector.open("sms://" + userNumber);
TextMessage txtmessage = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setPayloadText(text);
conn.send(txtmessage);