Rectangle 27 203

$ git clone https://android.googlesource.com/platform/frameworks/volley
$ cd volley
$ android update project -p .
$ ant jar
bin/volley.jar
libs/

NOTE: You will have to have fixed your PATH variable for this, to do this on linux do the following (in your .profile or wherever you put PATH variables): 1. export ANDROID_HOME=<android-sdk-dir>

Serious Question: Why is there no straight download of the volley Jar File anywhere? Is there some problem with one universal JAR file for it?

@ChintanSoni, ~ 3 months ago, git submission c9ef93a says "Migrate from Gradle to Maven." Instead of running "android update -p .", you run maven commands, "mvn compile" and then "mvn package."

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 203

$ git clone https://android.googlesource.com/platform/frameworks/volley
$ cd volley
$ android update project -p .
$ ant jar
bin/volley.jar
libs/

NOTE: You will have to have fixed your PATH variable for this, to do this on linux do the following (in your .profile or wherever you put PATH variables): 1. export ANDROID_HOME=<android-sdk-dir>

Serious Question: Why is there no straight download of the volley Jar File anywhere? Is there some problem with one universal JAR file for it?

@ChintanSoni, ~ 3 months ago, git submission c9ef93a says "Migrate from Gradle to Maven." Instead of running "android update -p .", you run maven commands, "mvn compile" and then "mvn package."

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 72

In the Volley lesson, Google instructs as to either add Volley to our project as an Android Library project or as a .jar file.

Here's how to create the Volley .jar file using Android Studio or Eclipse:

In both cases I suggest renaming the .jar file to the date of Volley's latest commit, i.e. volley_20150319.jar, to keep versioning simple.

  • Import the project into Android Studio. (I usually select the project's gradle file when importing in Android Studio)
  • Build the project. (I had to change the gradle build settings to reflect the latest build tools and gradle version, but it's usually up to date).
[your local path to volley]/build/intermediate/bundles/
  • In both the debug and release folders you'll find a JAR file called classes.jar.
libs/
  • Gradle sync, and you're done.
  • Clone the Volley repository via Git.
  • Import the project into eclipse.
  • Right-click the project and select Export...
  • We're only interested in the src folder and nothing else. The easiest way to make sure only it is selected is to deselect the project and then select the src folder inside.
  • OPTIONAL: If you want the Javadoc to be visible also select the Export Java source files resources.
  • Create the JAR file and put it in your libs/ folder.

This is great. The most important tip for me was #5 (select only src), as this helped with other libraries I was trying to include as well.

You save me a day! "only check src folder" works for me :)

This was the answer that helped me the most. Thanks @Itai!

this is the best and the easiest way.. thanks..

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 72

In the Volley lesson, Google instructs as to either add Volley to our project as an Android Library project or as a .jar file.

Here's how to create the Volley .jar file using Android Studio or Eclipse:

In both cases I suggest renaming the .jar file to the date of Volley's latest commit, i.e. volley_20150319.jar, to keep versioning simple.

  • Import the project into Android Studio. (I usually select the project's gradle file when importing in Android Studio)
  • Build the project. (I had to change the gradle build settings to reflect the latest build tools and gradle version, but it's usually up to date).
[your local path to volley]/build/intermediate/bundles/
  • In both the debug and release folders you'll find a JAR file called classes.jar.
libs/
  • Gradle sync, and you're done.
  • Clone the Volley repository via Git.
  • Import the project into eclipse.
  • Right-click the project and select Export...
  • We're only interested in the src folder and nothing else. The easiest way to make sure only it is selected is to deselect the project and then select the src folder inside.
  • OPTIONAL: If you want the Javadoc to be visible also select the Export Java source files resources.
  • Create the JAR file and put it in your libs/ folder.

This is great. The most important tip for me was #5 (select only src), as this helped with other libraries I was trying to include as well.

You save me a day! "only check src folder" works for me :)

This was the answer that helped me the most. Thanks @Itai!

this is the best and the easiest way.. thanks..

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 48

1) Is this library can also be used as networking library in normal Java projects also OR is it strictly for Android Only

It is for Android only, as it depends on Android-specific classes. You can tell this by looking at the source code, for stuff like RequestQueue.

2) I see multiple branches here and no documentation on which branch is to start with. Which branch should I use to start with?

3) How to integrate this library in your own project? What approach is better: Make Volley as a standalone library project and spin a jar and put it in your project or Copy the all source code inside your project?

The instructions from the Google I|O presentation were to add the source code to your project. Personally, I find this to be a bizarre approach.

Fatal: remote error: Access Denied (not available in your country)! If i download jar and add jar to my project does it work in my country? Or even how can i download jar, without cloning it?!

Yes, their instructions seem to suggest using 'master' branch, but I find this a bit odd given that master seems to be actively changing. Perhaps would be better to find the latest release branch.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 8

Here is a small Quickstart for a Volley Http Request, It is extremely easy to integrate.

You need an application wide Volley RequestQueue:

1. private static RequestQueue reqQueue;

You could put it in your Application class and make it statically available via getRequestQueue().

Then you can already use the RequestQueue.add() method to execute the first request with Volley.

2. reqQueue.add(...)
  • Use JsonObjectRequest to query for a single object, use JsonArrayRequest to query for a list of objects. queue.add(new JsonArrayRequest(URL, new Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { //SUCCESS }}, new ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //ERROR }}));

Remember to set the Http Expires header correctly on your server-side so Volley can make use of it's integrated caching feature

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 41

you can download the volley.jar

Volley.jar

Right Click volley.jar -> Add As Library

How about a new jar verson?

Nice work. Good for providing jar

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 13

Add it as library - (quick solution)

Since there are many answers about a single approach, but none that is comparing the different ways to get volley up and running, I also put my two cents in. Feel free to edit/enhance this answer as well.

[MyProjectPath]/app/libs/
right-click
Add As Library...
  • Download / install the git client (if you don't have it on your system yet) (othervise via git clone https://github.com/git/git ... sry bad one, but couldn't resist ^^)
git clone https://android.googlesource.com/platform/frameworks/volley

Copy the com folder from within [path_where_you_typed_git_clone]/volley/src to your projects app/src/main/java folder (or integrate it instead, if you already have a com folder there!! ;-))

The files show up immediately in Android Studio. For Eclipse you will have to right-click on the src folder and press refresh (or F5) first.

Doing it via git is what is officially suggested in the android tutorials (look here).

In your project's src/build.gradle file add following volley dependency:

dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        // ...

        compile 'com.mcxiaoke.volley:library:1.+'
    }

Click on Try Again which should right away appear on the top of the file, or just Build it if not

The main "advantage" here is, that this will keep the version up to date for you, whereas in the other two cases you would have to manually update volley.

On the "downside" it is not officially from google, but a third party weekly mirror.

But both of these points, are really relative to what you would need/want. Also if you don't want updates, just put the desired version there instead e.g. compile 'com.mcxiaoke.volley:library:1.0.7'.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 48

1) Is this library can also be used as networking library in normal Java projects also OR is it strictly for Android Only

It is for Android only, as it depends on Android-specific classes. You can tell this by looking at the source code, for stuff like RequestQueue.

2) I see multiple branches here and no documentation on which branch is to start with. Which branch should I use to start with?

3) How to integrate this library in your own project? What approach is better: Make Volley as a standalone library project and spin a jar and put it in your project or Copy the all source code inside your project?

The instructions from the Google I|O presentation were to add the source code to your project. Personally, I find this to be a bizarre approach.

Fatal: remote error: Access Denied (not available in your country)! If i download jar and add jar to my project does it work in my country? Or even how can i download jar, without cloning it?!

Yes, their instructions seem to suggest using 'master' branch, but I find this a bit odd given that master seems to be actively changing. Perhaps would be better to find the latest release branch.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 8

Here is a small Quickstart for a Volley Http Request, It is extremely easy to integrate.

You need an application wide Volley RequestQueue:

1. private static RequestQueue reqQueue;

You could put it in your Application class and make it statically available via getRequestQueue().

Then you can already use the RequestQueue.add() method to execute the first request with Volley.

2. reqQueue.add(...)
  • Use JsonObjectRequest to query for a single object, use JsonArrayRequest to query for a list of objects. queue.add(new JsonArrayRequest(URL, new Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { //SUCCESS }}, new ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //ERROR }}));

Remember to set the Http Expires header correctly on your server-side so Volley can make use of it's integrated caching feature

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 50

Volley doesn't actually make HTTP requests itself, and thus doesn't manage Cookies directly. It instead uses an instance of HttpStack to do this. There are two main implementations:

  • HurlStack: Uses HttpUrlConnection under the hood
  • HttpClientStack: uses Apache HttpClient under the hood

Cookie management is the responsibility of those HttpStacks. And they each handle Cookies differently.

If you need to support < 2.3, then you should use the HttpClientStack:

Configure an HttpClient instance, and pass that to Volley for it to use under the hood:

// If you need to directly manipulate cookies later on, hold onto this client
// object as it gives you access to the Cookie Store
DefaultHttpClient httpclient = new DefaultHttpClient();

CookieStore cookieStore = new BasicCookieStore();
httpclient.setCookieStore( cookieStore );

HttpStack httpStack = new HttpClientStack( httpclient );
RequestQueue requestQueue = Volley.newRequestQueue( context, httpStack  );

The advantage with this vs manually inserting cookies into the headers is that you get actual cookie management. Cookies in your store will properly respond to HTTP controls that expire or update them.

I've gone a step further and sub-classed BasicCookieStore so that I can automatically persist my cookies to disk.

HOWEVER! If you don't need to support older versions of Android. Just use this method:

// CookieStore is just an interface, you can implement it and do things like
// save the cookies to disk or what ever.
CookieStore cookieStore = new MyCookieStore();
CookieManager manager = new CookieManager( cookieStore, CookiePolicy.ACCEPT_ALL );
CookieHandler.setDefault( manager  );

// Optionally, you can just use the default CookieManager
CookieManager manager = new CookieManager();
CookieHandler.setDefault( manager  );

HttpURLConnection will query the CookieManager from that implicitly. HttpUrlConnection is also more performant and a bit cleaner to implement and work with IMO.

This worked for me. I wound up just using the default CookieManager. As a not, calling on CookieHandler.getDefault().put() requires a Map<String, List<String>>. The default implementation of put() parses the cookies out of the map and requires that the key is either (case insensitive) "set-cookie" or "set-cookie2". Had to examine the source to find that out.

@Adam, Thanks, I also used the default CookieManager, the headers are now correct. But when I redirect to another activity, those headers are not part of the request anymore even if I set cookiemanager onCreate of the activity, is there a way to make it persistent between activities?

Using cookies with Android volley library - Stack Overflow

android android-volley
Rectangle 27 41

you can download the volley.jar

Volley.jar

Right Click volley.jar -> Add As Library

How about a new jar verson?

Nice work. Good for providing jar

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 13

Add it as library - (quick solution)

Since there are many answers about a single approach, but none that is comparing the different ways to get volley up and running, I also put my two cents in. Feel free to edit/enhance this answer as well.

[MyProjectPath]/app/libs/
right-click
Add As Library...
  • Download / install the git client (if you don't have it on your system yet) (othervise via git clone https://github.com/git/git ... sry bad one, but couldn't resist ^^)
git clone https://android.googlesource.com/platform/frameworks/volley

Copy the com folder from within [path_where_you_typed_git_clone]/volley/src to your projects app/src/main/java folder (or integrate it instead, if you already have a com folder there!! ;-))

The files show up immediately in Android Studio. For Eclipse you will have to right-click on the src folder and press refresh (or F5) first.

Doing it via git is what is officially suggested in the android tutorials (look here).

In your project's src/build.gradle file add following volley dependency:

dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        // ...

        compile 'com.mcxiaoke.volley:library:1.+'
    }

Click on Try Again which should right away appear on the top of the file, or just Build it if not

The main "advantage" here is, that this will keep the version up to date for you, whereas in the other two cases you would have to manually update volley.

On the "downside" it is not officially from google, but a third party weekly mirror.

But both of these points, are really relative to what you would need/want. Also if you don't want updates, just put the desired version there instead e.g. compile 'com.mcxiaoke.volley:library:1.0.7'.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 24

The Volley library is now published by the Android Open Source Project:

dependencies {
    compile 'com.android.volley:volley:1.0.0'
}

Make sure you remove volley.jar from your libs folder, if you have in there. And, remove the reference to volley.jar from your app/build.gradle file.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 24

The Volley library is now published by the Android Open Source Project:

dependencies {
    compile 'com.android.volley:volley:1.0.0'
}

Make sure you remove volley.jar from your libs folder, if you have in there. And, remove the reference to volley.jar from your app/build.gradle file.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 15

UPDATE: Volley is now official and is available through the JCenter. Here's how to import it:

compile 'com.android.volley:volley:1.0.0'

If you're using Gradle, you can import Volley from here.

dependencies {
    compile 'com.mcxiaoke.volley:library:1.0.+'
}

This is an unofficial mirror (with some minor bugfix, see Changelog for details.) for android volley library, the source code will synchronize periodically with the official volley repository.

Where in the file should this be?

If you are using Gradle to build your app, should be build.gradle file in your project. If you aren't using Gradle, then take a look at other solutions posted here.

Thanks, but I meant where in the build.gradle file should the above be?

As The Metal Beard stated in his comment. Inside the dependencies if you have one already declared. If not, declare it at the end of the file, but don't include it inside android tag

NOTE: This is not official. It is a mirror of the Volley repo.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 15

UPDATE: Volley is now official and is available through the JCenter. Here's how to import it:

compile 'com.android.volley:volley:1.0.0'

If you're using Gradle, you can import Volley from here.

dependencies {
    compile 'com.mcxiaoke.volley:library:1.0.+'
}

This is an unofficial mirror (with some minor bugfix, see Changelog for details.) for android volley library, the source code will synchronize periodically with the official volley repository.

Where in the file should this be?

If you are using Gradle to build your app, should be build.gradle file in your project. If you aren't using Gradle, then take a look at other solutions posted here.

Thanks, but I meant where in the build.gradle file should the above be?

As The Metal Beard stated in his comment. Inside the dependencies if you have one already declared. If not, declare it at the end of the file, but don't include it inside android tag

NOTE: This is not official. It is a mirror of the Volley repo.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 11

If you use GIT for your own code management, why not simply add it as a submodule to project...

git submodule add https://android.googlesource.com/platform/frameworks/volley -b master Volley

That way, as the Volley code base is updated, it is simple to update...

git submodule git pull

You can extend the main Volley class in your own project for modification, which keeps you from having to mess with coding your changes every time the Volley framework is updated.

The problem is that the volley project is not defined as an android library.

You have to set Volley in your IDE as a library.

Doing this will modify the project property and so the submodule will be in state "modified". Because of that I do not want to use this solution. With a project "correctly defined", I would have use the submodule but not for Volley. I created a jar of Volley so far.

You can still pull from Google source as they make changes. If you are wanting to modify their code and store that, then clone it, make your local repo reference two different remotes, and use one to pull from them, and the other to push the code you want to store. I am not sure why it bothers you to have a submodule as modified, if you are storing your project anywhere, and you push from the parent project, without committing the submodule anywhere, you will still push in the reference to the commit of the submodule when you added it.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 11

If you use GIT for your own code management, why not simply add it as a submodule to project...

git submodule add https://android.googlesource.com/platform/frameworks/volley -b master Volley

That way, as the Volley code base is updated, it is simple to update...

git submodule git pull

You can extend the main Volley class in your own project for modification, which keeps you from having to mess with coding your changes every time the Volley framework is updated.

The problem is that the volley project is not defined as an android library.

You have to set Volley in your IDE as a library.

Doing this will modify the project property and so the submodule will be in state "modified". Because of that I do not want to use this solution. With a project "correctly defined", I would have use the submodule but not for Volley. I created a jar of Volley so far.

You can still pull from Google source as they make changes. If you are wanting to modify their code and store that, then clone it, make your local repo reference two different remotes, and use one to pull from them, and the other to push the code you want to store. I am not sure why it bothers you to have a submodule as modified, if you are storing your project anywhere, and you push from the parent project, without committing the submodule anywhere, you will still push in the reference to the commit of the submodule when you added it.

http - Volley Android Networking Library - Stack Overflow

android http android-networking android-volley
Rectangle 27 8

This error happens because the server sends a 401 (Unauthorized) but does not give a "WWW-Authenticate" which is a hint for the client what to do next. The "WWW-Authenticate" Header tells the client which kind of authentication is needed (either Basic or Digest). This is usually not very useful in headless http clients, but that's how the standard is defined. The error occurs because the lib tries to parse the "WWW-Authenticate" header but can't.

Possible solutions if you can change the server:

  • Add a fake "WWW-Authenticate" header like: WWW-Authenticate: Basic realm="fake". This is a mere workaround not a solution, but it should work and the http client is satisfied.
  • Use HTTP status code 403 instead of 401. It's semantic is not the same and usually when working with login 401 is a correct response (see here for a detailed discussion) but its close enough.

Possible solutions if you can't change the server:

As @ErikZ wrote in his post you could use a try&catch

HttpURLConnection connection = ...;
try {
    // Will throw IOException if server responds with 401.
    connection.getResponseCode(); 
} catch (IOException e) {
    // Will return 401, because now connection has the correct internal state.
    int responsecode = connection.getResponseCode(); 
}

I'm trying to send a header with Digest authentication, but can't figured out how to do it (still searching for an answer). Do you have any sample on how to do a Digest (or even basic) authentication in Android-Volley?

Basic and Digest is just putting a header that looks like this "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" in Basic and more complicated in digest - this is not special to volley, you just put set headers (google on how to do that in volley)

I'm sorry I asked this question so long ago I don't even remember what it relates to, plus that legacy project has been shut down. I'll upvote your answer for effort you've put in, but have no way of checking it's right so won't select it as the answer I'm afraid.

Fair enough. Ill leave it since it took me quite a while to understand the problem - learning REST/HTTP spec isn't sometimes as straight forward as you think :)

how to add WWW-Authenticate header in the server response

android - volley error No authentication challenges found - Stack Over...

android authentication android-volley