Search in sources :

Example 11 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class BlackBerryImplementation method sendMessage.

public void sendMessage(String[] recipients, String subject, Message msg) {
    Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);
    net.rim.blackberry.api.mail.Message message = new net.rim.blackberry.api.mail.Message(folders[0]);
    try {
        Address[] toAdds = new Address[recipients.length];
        for (int i = 0; i < recipients.length; i++) {
            Address address = new Address(recipients[i], "");
            toAdds[i] = address;
        }
        message.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAdds);
        message.setSubject(subject);
    } catch (Exception e) {
        EventLog.getInstance().logErrorEvent("err " + e.getMessage());
    }
    try {
        if (msg.getAttachment() != null && msg.getAttachment().length() > 0) {
            Multipart content = new Multipart();
            TextBodyPart tbp = new TextBodyPart(content, msg.getContent());
            content.addBodyPart(tbp);
            InputStream stream = com.codename1.io.FileSystemStorage.getInstance().openInputStream(msg.getAttachment());
            byte[] buf;
            buf = IOUtilities.streamToBytes(stream);
            stream.close();
            String name = msg.getAttachment();
            name = name.substring(name.lastIndexOf(getFileSystemSeparator()) + 1, name.length());
            SupportedAttachmentPart sap = new SupportedAttachmentPart(content, msg.getAttachmentMimeType(), name, buf);
            content.addBodyPart(sap);
            message.setContent(content);
        } else {
            message.setContent(msg.getContent());
        }
        app.setWaitingForReply(true);
        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
    } catch (Exception ex) {
        EventLog.getInstance().logErrorEvent("err " + ex.getMessage());
    }
}
Also used : Multipart(net.rim.blackberry.api.mail.Multipart) TextMessage(javax.wireless.messaging.TextMessage) Message(com.codename1.messaging.Message) Address(net.rim.blackberry.api.mail.Address) BufferedInputStream(com.codename1.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) TextBodyPart(net.rim.blackberry.api.mail.TextBodyPart) Folder(net.rim.blackberry.api.mail.Folder) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) MessageArguments(net.rim.blackberry.api.invoke.MessageArguments) SupportedAttachmentPart(net.rim.blackberry.api.mail.SupportedAttachmentPart)

Example 12 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class IntentIntegrator method showDownloadDialog.

private void showDownloadDialog() {
    Dialog d = new Dialog();
    d.setTitle(title);
    if (Dialog.show(title, message, "Yes", "No")) {
        Uri uri = Uri.parse("market://details?id=" + BS_PACKAGE);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        try {
            activity.startActivity(intent);
        } catch (ActivityNotFoundException anfe) {
            // Hmm, market is not installed
            Log.w(TAG, "Android Market is not installed; cannot install Barcode Scanner");
        }
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Dialog(com.codename1.ui.Dialog) Intent(android.content.Intent) Uri(android.net.Uri)

Example 13 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class AnalyticsService method sendCrashReport.

/**
 * In apps mode we can send information about an exception to the analytics server
 * @param t the exception
 * @param message up to 150 character message,
 * @param fatal is the exception fatal
 */
public static void sendCrashReport(Throwable t, String message, boolean fatal) {
    // https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#exception
    ConnectionRequest req = GetGARequest();
    req.addArgument("t", "exception");
    System.out.println(message);
    req.addArgument("exd", message.substring(0, Math.min(message.length(), 150) - 1));
    if (fatal) {
        req.addArgument("exf", "1");
    } else {
        req.addArgument("exf", "0");
    }
    NetworkManager.getInstance().addToQueue(req);
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 14 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class FacebookConnect method validateToken.

@Override
protected boolean validateToken(String token) {
    // make a call to the API if the return value is 40X the token is not
    // valid anymore
    final boolean[] retval = new boolean[1];
    retval[0] = true;
    ConnectionRequest req = new ConnectionRequest() {

        @Override
        protected void handleErrorResponseCode(int code, String message) {
            // access token not valid anymore
            if (code >= 400 && code <= 410) {
                retval[0] = false;
                return;
            }
            super.handleErrorResponseCode(code, message);
        }
    };
    req.setPost(false);
    req.setUrl("https://graph.facebook.com/v2.4/me");
    req.addArgumentNoEncoding("access_token", token);
    NetworkManager.getInstance().addToQueueAndWait(req);
    return retval[0];
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 15 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class GoogleConnect method validateToken.

@Override
protected boolean validateToken(String token) {
    // make a call to the API if the return value is 40X the token is not
    // valid anymore
    final boolean[] retval = new boolean[1];
    retval[0] = true;
    ConnectionRequest req = new ConnectionRequest() {

        @Override
        protected void handleErrorResponseCode(int code, String message) {
            // access token not valid anymore
            if (code >= 400 && code <= 410) {
                retval[0] = false;
                return;
            }
            super.handleErrorResponseCode(code, message);
        }
    };
    req.setPost(false);
    req.setUrl("https://www.googleapis.com/plus/v1/people/me");
    req.addRequestHeader("Authorization", "Bearer " + token);
    NetworkManager.getInstance().addToQueueAndWait(req);
    return retval[0];
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Aggregations

ConnectionRequest (com.codename1.io.ConnectionRequest)8 ActionListener (com.codename1.ui.events.ActionListener)6 IOException (java.io.IOException)5 Message (au.com.dius.pact.model.v3.messaging.Message)4 ActionEvent (com.codename1.ui.events.ActionEvent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 MessagePact (au.com.dius.pact.model.v3.messaging.MessagePact)2 BufferedInputStream (com.codename1.io.BufferedInputStream)2 NetworkEvent (com.codename1.io.NetworkEvent)2 Message (com.codename1.messaging.Message)2 Dialog (com.codename1.ui.Dialog)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 DataInputStream (java.io.DataInputStream)2 Method (java.lang.reflect.Method)2 Hashtable (java.util.Hashtable)2 Vector (java.util.Vector)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1