0

我正在尝试在 Android 上实现和使用 Exchange Web 服务。我找到了这篇文章,并以同样的方式安装了 Microsoft 的 EWS API JAVA:

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

我编写并执行了一个发送消息的简单示例。但我得到了这个错误:

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

有人可以帮助我吗?有没有人可以分享的样本?谢谢!

这是示例:

    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(
                            "sample@gmail.com",
                            "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("sample@gmail.com");
                    msg.send();

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

我使用 Android 2.2 作为平台,Java 编译器 1.6

4

1 回答 1

1

有一个商业 ActiveSync 库可用@JWebServices 用于 java 和 android。在该页面下载 JWebServices for Exchange。下载后,只需将 jwebservices-1.1.jar jar 文件添加到您的项目中,您只需在您的代码中创建服务对象时提供信息,如下所示。它在我的安卓应用程序中工作。

Service service = new Service( "https://mail.yourdomain.com/ews/Exchange.asmx", "emailid@yourdomain.com", "password");

这是显示当前时间和接下来 12 小时之间的约会的示例代码。

Service service = new Service(
                    "https://mail.yourdomain.com/ews/Exchange.asmx",
                    "emailid@yourdomain.com", "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()); } }
于 2013-09-23T10:44:52.217 回答