Reputation: 215
im trying Sardine to make a webdav client in android, im trying this code:
This works perfect on JAVA aplicacion, but crashes in android :(
HttpClient client = new DefaultHttpClient();
SardineImpl sardine = new SardineImpl((AbstractHttpClient) client,"testuser","test");
List<DavResource> resources = sardine.getResources("http://demo.sabredav.org/");
for (int i = 1; i < resources.size(); i++) {
System.out.println(resources.get(i));
}
Replacing System.out.println
by Toast
i get this
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): java.lang.NoSuchMethodError: org.apache.http.impl.client.AbstractHttpClient.setRedirectStrategy
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.googlecode.sardine.impl.SardineImpl.init(SardineImpl.java:188)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.googlecode.sardine.impl.SardineImpl.<init>(SardineImpl.java:182)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at es.sardine.sardine.onCreate(sardine.java:39)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.os.Looper.loop(Looper.java:143)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at android.app.ActivityThread.main(ActivityThread.java:4914)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at java.lang.reflect.Method.invoke(Method.java:521)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 0
Views: 3747
Reputation: 2856
I had the same trouble trying to use Sardine and including Apache HttpClient which would conflict with the version embedded in Android. So I decided to replace it with OkHttp and I have much less trouble. Here is the fork I created: https://github.com/thegrizzlylabs/sardine-android
Upvotes: 1
Reputation: 25
For you only iterating through the elements on the server this code worked for me:
try{
Sardine sardine = SardineFactory.begin("username", "password");
List<DavResource> resources = sardine.list("webdav/server/directory/");
buffer = new StringBuilder();
for (DavResource res : resources)
{
//for example
buffer.append(res.toString());
}
}catch(Exception e){
Log.e("VIEWER" , e.getMessage());
}
I used the Sardine-Android Project Library in combination with the simpleframework.xml.
Upvotes: 0
Reputation: 6988
Did you see this q: Using webdav on Android ? It essentially says that Sardine needs newer HttpClient version than packages with Android, and provides a lick to patched HttpClient 4.1 linkable into Android apps.
Upvotes: 0