I want to use the EWS-Java-API for my android application. The application requires a login to get programmatically access to the microsoft exchange server (e.g. calendar meetings, email, meeting rooms, and much more).
At this point almost the entire question is edited, just in case to show the situation so far.
I try to get connected to an exchange version 15.0.11 with the url ("https ://yourserver/EWS/Exchange.asmx")
Build gradle file:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
} [...] }
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.3.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'org.altbeacon:android-beacon-library:2.7.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile files('libs/jcifs-1.3.15.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/commons-codec-1.4.jar')
compile files('libs/commons-httpclient-3.1.jar')
compile 'com.microsoft.ews-java-api:ews-java-api:2.0' }
This will cause into this error message
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/protocol/HttpClientContext;
Line:
ExchangeService service = new ExchangeService();
At this point i tested this ews libary "github.com/faisons/EWS-For-Android".
compile files('libs/ews.jar')
This is almost working. Iam able to start the application and set up the ExchangeService.
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials(myuser, mypw);
service.setCredentials(credentials);
service.setUrl(new URI("https://exchmail.yourserver.com/EWS/Exchange.asmx"));
EmailMessage message = new EmailMessage(service);
EmailAddress from = new EmailAddress(myemail);
message.setSender(from);
message.getToRecipients().add(anotherEmail);
message.setSubject("Much wow - such message");
MessageBody messageBody = new MessageBody();
messageBody.setText("text here");
message.setBody(messageBody);
message.send();
}
catch (Exception e)
{
Log.e(TAG, "message", e);
}
}
});
thread.start();
The error now is:
java.lang.NullPointerException: format == null
at java.lang.String.format(String.java:1799)
at java.lang.String.format(String.java:1777)
at java.lang.String.format(String.java:1799)
at microsoft.exchange.webservices.data.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:936)
at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:821)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:46)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:143)
at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:463)
at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:534)
at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:215)
at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:125)
Iam confused how to get the api working. If somebody knows another way to get access any hint is welcome!