Accessing FAT32 and NTFS format USB Pendrive from android tablet

Bala picture Bala · Aug 28, 2012 · Viewed 12.2k times · Source

We have a USB port in our android tablet(version 4.0.3).

Pendrive File Systems Format are

  1. NTFS
  2. FAT32

When Pendrive File Systems Format are FAT32 File has been created Successfully. But When File Systems Format are NTFS, I got the Error Message as open failed: EACCESS (Permission denied).

I Need to create a New File from in the USB Pendrive. I have tried my sample code is

Button createFile = (Button) findViewById(R.id.createFile);
createFile.setOnClickListener(new OnClickListener() 
{
    public void onClick(View v) 
    {
        try 
        {
            File root = new File("/mnt/usbhost1");
            Runtime.getRuntime().exec("chmod 777 " + root.getAbsolutePath());
            File myFile = new File(root,"createNew.txt");
            myFile.createNewFile();
            Toast.makeText(getBaseContext(), "Done Creating File", Toast.LENGTH_SHORT).show();
        } 
        catch (Exception e) 
        {
            Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }
});

Here /usbhost1 is a Android tablet USB Path. Where I am mistaken. How to create a New File from in the NTFS File Systems Format.

Thanks in advance.

Regards
Bala

Answer

TheCodeArtist picture TheCodeArtist · Oct 8, 2012

What you need is a way to enable support for NTFS in the kernel on your device. This could be achieved dynamically by building the ntfs-driver as loadable module (.ko file). This would need to be done for the specific version of the kernel that is running on your device.

Next you need a way to automatically load the module each time the systems restarts. this is also "do-able" in Android. You might want to try this app which does precisely that. i.e. load one or more kernel module(s) located anywhere on the Android device.

After this whenever one inserts a external-device(usb-drive) that has ntfs partitions, the kernel will be able to properly recognise and mount it. Hence apps can then access it at its proper location like "/mnt/usbhost1" etc.