Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SMB protocol in URL while using JCIFS library on Android

I'm using JCIFS in my new Android project. Somehow I've decided to use URL class to generalized the file path (so I can add more protocol later). What I did is as below

URL url = new URL("smb://192.168.1.1/filepath");

And then java.net.MalformedURLException exception is thrown.

Exception in thread "main" java.net.MalformedURLException: unknown protocol: smb
    at java.net.URL.<init>(URL.java:184)
    at java.net.URL.<init>(URL.java:127)

Consulting JCIFS FAQ reveals that I have to register the protocol before using the class. However I don't really know how to do so in Android. I think the library do this already, but it doesn't on Android.

So what should I do ?

like image 267
mr_tawan Avatar asked Jul 22 '12 07:07

mr_tawan


1 Answers

I've just saw the usage in JCIFS reference, in the SmbFile reference.

When using the java.net.URL class with 'smb://' URLs it is necessary to first call the static jcifs.Config.registerSmbURLHandler(); method. This is required to register the SMB protocol handler.

So I add this call and it works properly.

like image 52
mr_tawan Avatar answered Oct 12 '22 22:10

mr_tawan