[英]Exchange Web Services on Android, error
I'm trying to implement and use Exchange Web Services on Android. 我正在尝试在Android上实现和使用Exchange Web服务。 I found this post and I proceed the same way by installing the Microsoft's EWS API JAVA: 我找到了这篇文章,并通过安装Microsoft的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(
"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());
}
}
});
}
}
I'm using Android 2.2 as Platform, Java Compiler 1.6 我正在使用Android 2.2作为平台,Java Compiler 1.6
There's a commercial ActiveSync library available @ JWebServices for java and android . JWebServices提供了一个用于Java和android的商业ActiveSync库。 Download JWebServices for Exchange in that page. 在该页面中下载JWebServices for Exchange。 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. 下载后,只需将jwebservices-1.1.jar jar文件添加到您的项目中,您只需在用您的代码创建Service对象时提供信息即可,如下所示。 It worked in my android app. 它在我的Android应用程序中有效。
Service service = new Service( "https://mail.yourdomain.com/ews/Exchange.asmx", "emailid@yourdomain.com", "password");
Here is the example code to display the appointments between current time and next 12 hours. 这是示例代码,用于显示当前时间和接下来的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()); } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.