2

This is my demo code Can anyone help me to come out of this error ? I am getting the following exception for my code (Could not read file) IllegalArgumentException.

09-22 10:29:22.485  13759-13759/com.abc.xyz E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.abc.xyz, PID: 13759
        java.lang.IllegalArgumentException: Could not read file
                at org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer.sendFile(OutgoingFileTransfer.java:220)
                at com.abc.xyz.FileTransferActivity.transferFile(FileTransferActivity.java:93)
                at com.abc.xyz.FileTransferActivity.onClick(FileTransferActivity.java:77)
                at android.view.View.performClick(View.java:4780)
                at android.view.View$PerformClick.run(View.java:19866)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:135)
                at android.app.ActivityThread.main(ActivityThread.java:5254)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

This is the code

private void transferFile(final String filePath) {

    FileTransferManager fileTransferManager = FileTransferManager.getInstanceFor(MainActivity.Connection);
    OutgoingFileTransfer transfer = fileTransferManager.createOutgoingFileTransfer("abc@blackberry-pc/developers");
    try
    {
        transfer.sendFile(new File(filePath),"");
    }
    catch (SmackException e)
    {
        e.printStackTrace();
    }

    //RECEIVE FILES
    fileTransferManager.addFileTransferListener(new FileTransferListener() {
        @Override
        public void fileTransferRequest(FileTransferRequest request) {
            IncomingFileTransfer transfer = request.accept();
            try {
                transfer.recieveFile(new File(filePath));
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
Tony Stark
  • 451
  • 1
  • 3
  • 11

1 Answers1

0

You cannot directly access since Android 4.4, to any file in your SD card that is not inside your package directories. Check this answer, here it tells you how to access your package files inside the SD card and how to create such directories.

Once you have created these directories and have put the files inside, you will be able to access your files without problem.

If, on the contrary, you want to access to any file in your SD card, there is a workaround for 4.4+ which will probably enable you to do so. But I do not recommend it

Hope it helps

Community
  • 1
  • 1
zozelfelfo
  • 3,776
  • 2
  • 21
  • 35