user1966941
user1966941

Reputation: 1

Exchange Web Services on Android, error

I'm trying to implement and use Exchange Web Services on Android. I found this post and I proceed the same way by installing the Microsoft's EWS API JAVA:

http://stackoverflow.com/questions/7476055/use-exchange-web-services-on-android

I wrote and executed a simple sample that sends a message. But I obtained this error:

java.lang.VerifyError: microsoft.exchange.webservices.data.ExchangeServiceBase

May anybody help me? Is there any sample anybody might share? Thanks!

This is the sample:

    package com.example.ewsandroid;
import java.net.URI;
import java.util.Locale;
import microsoft.exchange.webservices.data.EmailMessage;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.MessageBody;
import microsoft.exchange.webservices.data.WebCredentials;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    

        final Button mButton = (Button) findViewById(R.id.button);

        mButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                Locale.setDefault(Locale.ENGLISH);
                try {
                    ExchangeService service = new ExchangeService();
                    WebCredentials webCredentials = new WebCredentials(
                            "[email protected]",
                            "sample");
                    URI url = new URI("https://sample.sample.com/ews/Exchange.asmx");
                    service.setCredentials(webCredentials);
                    service.setUrl(url);

                    EmailMessage msg= new EmailMessage(service);
                    msg.setSubject("Hello world!");
                    msg.setBody(MessageBody.getMessageBodyFromText
                               ("Sent using the EWS Managed API."));
                    msg.getToRecipients().add("[email protected]");
                    msg.send();

                } catch (Exception ex) {
                    System.out.println(ex.toString());
                }
            }
        });
    }   
}

I'm using Android 2.2 as Platform, Java Compiler 1.6

Upvotes: 0

Views: 1844

Answers (1)

Shivanand Darur
Shivanand Darur

Reputation: 3224

There's a commercial ActiveSync library available @ JWebServices for java and android. Download JWebServices for Exchange in that page. Once you download , Just add jwebservices-1.1.jar jar file to ur project and u just have to provide the info while creating the Service object in ur code, as shown below. It worked in my android app.

Service service = new Service( "https://mail.yourdomain.com/ews/Exchange.asmx", "[email protected]", "password");

Here is the example code to display the appointments between current time and next 12 hours.

Service service = new Service(
                    "https://mail.yourdomain.com/ews/Exchange.asmx",
                    "[email protected]", "password");
            Date startDate = new Date(System.currentTimeMillis());
            Date endDate = new Date(System.currentTimeMillis()
                    + (12 * 60 * 60 * 1000));

            CharSequence startTime = DateFormat.format(
                    "yyyy-MM-dd HH:mm:ss", startDate);

            CharSequence endTime = DateFormat.format("yyyy-MM-dd HH:mm:ss",
                    endDate);

            IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(
                    AppointmentPropertyPath.START_TIME,
                    startTime.toString());
            IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(
                    AppointmentPropertyPath.END_TIME, endTime.toString());
            And restriction3 = new And(restriction1, restriction2);

            FindItemResponse response = service.findItem(
                    StandardFolder.CALENDAR,
                    AppointmentPropertyPath.getAllPropertyPaths(),
                    restriction3);
            int numberOfItems = response.getItems().size();
            if (numberOfItems <= 0)
                Log.v(">>><<<<", "There are no Appointments..");
            for (int i = 0; i < numberOfItems; i++) {
                if (response.getItems().get(i) instanceof Appointment) {
                    Appointment appointment = (Appointment) response
                            .getItems().get(i);
                    String logicalRoomName = null, location = appointment
                            .getLocation();
                    Log.v(">>><<<<", "Location = " + location);
                    Log.v(">>><<<<",
                            "Subject = " + appointment.getSubject());
                    Log.v(">>><<<<",
                            "StartTime = " + appointment.getStartTime());
                    Log.v(">>><<<<",
                            "EndTime = " + appointment.getEndTime());
                    Log.v(">>><<<<",
                            "Body Preview = "
                                    + appointment.getBodyPlainText()); } }

Upvotes: 1

Related Questions