我正在尝试在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
答案 0 :(得分:1)
@ JWebServices for java and android有一个商业ActiveSync库。在该页面下载JWebServices for Exchange。下载后,只需将jwebservices-1.1.jar jar文件添加到ur项目中,只需在ur代码中创建Service对象时提供信息,如下所示。它适用于我的Android应用程序。
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()); } }