我正在尝试在 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