0

For my android app I'm using a json file to inflate the app with content.

If I open the file from the assets folder, everything works fine. I'm opening the file simply by:

InputStream stream = getAssets().open("myfile.json");

Now I've placed the same file on a server. How should I get this file from an url? For example: http://myurl.com/myfile.json

I've tried the following:

BufferedInputStream stream = null;

    try {
        URL fileURL = new URL("http://myurl.com/myfile.json");
        URLConnection connection = fileURL.openConnection();
        connection.connect();
        stream = new java.io.BufferedInputStream(connection.getInputStream());

    } catch (Exception e) {
        Log.e("MY_LOG_TAG", "I got an error", e);
    }

It's not working, I'm recieving a 'Permission Denied' error. But the file is accessible. How to do this properly?

Trekdrop
  • 457
  • 7
  • 26
  • 1
    You are probably missing Internet permissions, see http://stackoverflow.com/questions/2169294/how-to-add-manifest-permission-to-android-application – Vincent Apr 11 '16 at 13:36
  • Do you have the internet permission declared in your manifest? – Remco Apr 11 '16 at 13:36
  • Please share your stacktrace, so that we know about the exact error – Jigar Apr 11 '16 at 13:38

1 Answers1

0

I was missing internet pemissions. In the manifest add:

<uses-permission android:name="android.permission.INTERNET" />
Trekdrop
  • 457
  • 7
  • 26