Exchange Web服务,在Android上的错误 [英] Exchange Web Services on Android, error

查看:173
本文介绍了Exchange Web服务,在Android上的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现和使用Exchange Web服务在Android上。我发现这个职位,我继续以同样的方式通过安装微软的EWS API JAVA:

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!

这是该示例:

    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

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

推荐答案

有名额 JWebServices的Java商业ActiveSync的图书馆,机器人。在该页面下载JWebServices的Exchange。一旦你下载,只要jwebservices-1.1.jar JAR文件添加到乌尔项目和u只需要提供信息,同时创造在乌拉圭回合code中的服务对象,如下图所示。它曾在我的Andr​​oid应用程序。

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服务=新服务(                         https://mail.yourdomain.com/ews/Exchange.asmx                         emailid@yourdomain.com,密码);

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

下面是例子code,显示当前时间和未来12小时的预约。

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",
                    "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()); } }

这篇关于Exchange Web服务,在Android上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆