Android NFS Client" → Android NFS Client

How can I mount a shared directory from a server to an Android app?

I am developing an Android NFS Client using the ‘nfs-client-java’ library. I am able to access and create files on the server, but I cannot mount the whole shared directory from the server.

On a Linux NFS Client, I can mount a shared directory from the server using the following command:

mount -t nfs -o nolock,rw,vers=3 192.168.1.10:/media/user/ /mnt/media_rw/remote

where /mnt/media_rw/remote is where the shared directory will be mounted.

Is there a way to achieve the same result using an Android app?

Yes, you can achieve the same result using the nfs-client-java library in your Android app. Here’s an example code snippet that you can modify to fit your specific use case:

import com.github.mjdev.libaums.fs.AfsFileSystemCreator;
import com.github.mjdev.libnfs.NfsFileSystem;
import com.github.mjdev.libnfs.NfsMount;
import com.github.mjdev.libnfs.Share;

// ...

// Create a new NFS mount object
NfsMount nfsMount = new NfsMount();

// Set the NFS server IP address
nfsMount.setServerAddress("192.168.1.10");

// Set the shared directory path on the server
Share share = new Share();
share.setRemotePath("/media/user/");
nfsMount.setShare(share);

// Set the local directory path where the shared directory will be mounted
nfsMount.setLocalMountPoint("/mnt/media_rw/remote");

// Set the NFS mount options
nfsMount.setMountOptions("nolock,rw,vers=3");

// Mount the shared directory
NfsFileSystem nfsFileSystem = nfsMount.mount();

// Use the NFS client to access and create files on the server
// ...

// Unmount the shared directory when you're done
nfsFileSystem.umount();

Note: You may need to add the libnfs and libaums libraries to your project’s dependencies.