ygesher
ygesher

Reputation: 1161

cn1 - download file to phone's download directory

I'm trying to allow an app to download files to the public 'Downloads' directory so it's available on the device in a generic fashion. I succeeded in downloading the files in the simulator to the .cn1 directory on my computer, but I couldn't find a straightforward way to get the file into a public directory on the device. I really expected there to be a method in the FileSystemStorage class that would allow this, but none of them seem to be what I'm looking for.

So I tried writing a simple native bridge to get the path to the public directory, starting with Android. I have a very simple class that looks like this:

public class DownloadDirectoryImpl {

    public static String getDownloadDirectory(){
        return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
    }

    public boolean isSupported(){
        return true;
    }
}

The app compiles fine, but when I click on the file to download it, I see the same line repeating itself in the logcat a few thousand times:

W/System.err:     at net.gesher.downloadDirectory.NativeDownloadDirectoryImpl.getDeviceDownloadDirectory(NativeDownloadDirectoryImpl.java:20)

But it doesn't state what the error is.

So, I'm looking for advice either a) to improve my android code so that it works, or b) the cn1 proper way of getting this directory path.

Thanks a ton!

Upvotes: 2

Views: 108

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

If you have a lot of lines saying at... and all refer to the same method then you have a recursive call leading to a stack overflow. Since the only method you mentioned is your native method I'm assuming you called your own method within the native implementation and got into a recursive loop.

Upvotes: 0

Related Questions