From: David A. Velasco Date: Tue, 17 Jul 2012 12:51:36 +0000 (+0200) Subject: Avoid crashes when an external app makes a bad response for the selection of a file... X-Git-Tag: oc-android-1.4.3~268 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/463b30c46a57df8c298be9d5b196e8e0330a0b73?ds=inline Avoid crashes when an external app makes a bad response for the selection of a file to upload --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 362a6018..9e2a64ad 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.163B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/res/values/strings.xml b/res/values/strings.xml index c53e475a..77796292 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -132,4 +132,6 @@ "Successful removal" "Removal could not be completed" + "Unexpected problem ; please, try other app to select the file" + diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 45f7c77d..81a8da1b 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -48,6 +48,7 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.OnNavigationListener; @@ -223,20 +224,29 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ACTION_SELECT_FILE) { if (resultCode == RESULT_OK) { - Uri selectedImageUri = data.getData(); - - String filemanagerstring = selectedImageUri.getPath(); - String selectedImagePath = getPath(selectedImageUri); - String filepath; - - if (selectedImagePath != null) - filepath = selectedImagePath; - else - filepath = filemanagerstring; - - if (filepath == null) { - Log.e("FileDisplay", "Couldnt resolve path to file"); - return; + String filepath = null; + try { + Uri selectedImageUri = data.getData(); + + String filemanagerstring = selectedImageUri.getPath(); + String selectedImagePath = getPath(selectedImageUri); + + if (selectedImagePath != null) + filepath = selectedImagePath; + else + filepath = filemanagerstring; + + } catch (Exception e) { + Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e); + e.printStackTrace(); + + } finally { + if (filepath == null) { + Log.e("FileDisplay", "Couldnt resolve path to file"); + Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG); + t.show(); + return; + } } Intent i = new Intent(this, FileUploader.class);