[英]Exchange Web Services on Android, error
我正在嘗試在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 Compiler 1.6
JWebServices提供了一個用於Java和android的商業ActiveSync庫。 在該頁面中下載JWebServices for Exchange。 下載后,只需將jwebservices-1.1.jar jar文件添加到您的項目中,您只需在用您的代碼創建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()); } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.