Skip to content

Commit

Permalink
Fixed issue #1 (IOException: exceeded content-length limit of xxx byt…
Browse files Browse the repository at this point in the history
…es). Fixed problem with multiple dialog when Locus is not installed. Changed version.
  • Loading branch information
arcao committed Nov 7, 2011
1 parent e019dcc commit 96bdc75
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .classpath
Expand Up @@ -4,5 +4,5 @@
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="lib/jdom.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arcao.geocaching4locus"
android:versionName="1.3.6.1" android:versionCode="11">
android:versionName="1.3.6.2" android:versionCode="12">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="4"></uses-sdk>
Expand Down
2 changes: 1 addition & 1 deletion default.properties → project.properties
Expand Up @@ -4,7 +4,7 @@
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# "ant.properties", and override values to adapt the script to your
# project structure.

# Project target.
Expand Down
5 changes: 4 additions & 1 deletion src/com/arcao/geocaching4locus/MainActivity.java
Expand Up @@ -56,6 +56,7 @@ public class MainActivity extends Activity implements LocationListener {
private EditText longitudeEditText;
private CheckBox simpleCacheDataCheckBox;
private CheckBox importCachesCheckBox;
private boolean locusInstalled = true;

/** Called when the activity is first created. */
@Override
Expand All @@ -68,6 +69,7 @@ public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "Locus version: " + locusVersion);

if (locusVersion.compareTo(LOCUS_MIN_VERSION) < 0) {
locusInstalled = false;
showError(locusVersion == Version.emptyVersion ? R.string.error_locus_not_found : R.string.error_locus_old, LOCUS_MIN_VERSION.toString(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -161,7 +163,8 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
});

if (!hasCoordinates) {
acquireCoordinates();
if (locusInstalled)
acquireCoordinates();
} else {
updateCoordinateTextView();
requestProgressUpdate();
Expand Down
17 changes: 8 additions & 9 deletions src/geocaching/api/impl/LiveGeocachingApi.java
Expand Up @@ -19,7 +19,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -234,8 +233,9 @@ protected JsonReader callPost(String function, String postBody) throws Geocachin

Log.i(TAG, "Posting " + maskPassword(function));


try {
byte[] data = postBody.getBytes("UTF-8");

URL url = new URL(BASE_URL + function);
HttpURLConnection con = (HttpURLConnection) url.openConnection();

Expand All @@ -247,19 +247,18 @@ protected JsonReader callPost(String function, String postBody) throws Geocachin

con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Content-Length", Integer.toString(postBody.length()));
con.setRequestProperty("Content-Length", Integer.toString(data.length));
//con.setRequestProperty("User-Agent", "Geocaching/4.0 CFNetwork/459 Darwin/10.0.0d3");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Accept-Language", "en-US");
con.setRequestProperty("Accept-Encoding", "gzip, deflate");

OutputStream os = con.getOutputStream();
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");


Log.i(TAG, "Body: " + postBody);
osr.write(postBody);
osr.flush();
osr.close();
os.write(data);
os.flush();
os.close();

if (con.getResponseCode() < 400) {
is = con.getInputStream();
Expand All @@ -284,7 +283,7 @@ protected JsonReader callPost(String function, String postBody) throws Geocachin
return new JsonReader(isr);
} catch (Exception e) {
Log.e(TAG, e.toString(), e);
throw new GeocachingApiException("Error while downloading data (" + e.getClass().getSimpleName() + ")", e);
throw new GeocachingApiException("Error while downloading data (" + e.getClass().getSimpleName() + "): " + e.getMessage(), e);
}
}

Expand Down

0 comments on commit 96bdc75

Please sign in to comment.