Avoid crashes when an external app makes a bad response for the selection of a file...
authorDavid A. Velasco <dvelasco@solidgear.es>
Tue, 17 Jul 2012 12:51:36 +0000 (14:51 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 17 Jul 2012 12:51:36 +0000 (14:51 +0200)
AndroidManifest.xml
res/values/strings.xml
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

index 362a601..9e2a64a 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.162B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.163B" xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
index c53e475..7779629 100644 (file)
        <string name="remove_success_msg">"Successful removal"</string>
        <string name="remove_fail_msg">"Removal could not be completed"</string>
        
+       <string name="filedisplay_unexpected_bad_get_content">"Unexpected problem ; please, try other app to select the file"</string>
+       
 </resources>
index 45f7c77..81a8da1 100644 (file)
@@ -48,6 +48,7 @@ import android.view.ViewGroup;
 import android.widget.ArrayAdapter;\r
 import android.widget.EditText;\r
 import android.widget.TextView;\r
+import android.widget.Toast;\r
 \r
 import com.actionbarsherlock.app.ActionBar;\r
 import com.actionbarsherlock.app.ActionBar.OnNavigationListener;\r
@@ -223,20 +224,29 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
         if (requestCode == ACTION_SELECT_FILE) {\r
             if (resultCode == RESULT_OK) {\r
-                Uri selectedImageUri = data.getData();\r
-    \r
-                String filemanagerstring = selectedImageUri.getPath();\r
-                String selectedImagePath = getPath(selectedImageUri);\r
-                String filepath;\r
-    \r
-                if (selectedImagePath != null)\r
-                    filepath = selectedImagePath;\r
-                else\r
-                    filepath = filemanagerstring;\r
-    \r
-                if (filepath == null) {\r
-                    Log.e("FileDisplay", "Couldnt resolve path to file");\r
-                    return;\r
+                String filepath = null;\r
+                try {\r
+                    Uri selectedImageUri = data.getData();\r
+    \r
+                    String filemanagerstring = selectedImageUri.getPath();\r
+                    String selectedImagePath = getPath(selectedImageUri);\r
+    \r
+                    if (selectedImagePath != null)\r
+                        filepath = selectedImagePath;\r
+                    else\r
+                        filepath = filemanagerstring;\r
+                    \r
+                } catch (Exception e) {\r
+                    Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);\r
+                    e.printStackTrace();\r
+                    \r
+                } finally {\r
+                    if (filepath == null) {\r
+                        Log.e("FileDisplay", "Couldnt resolve path to file");\r
+                        Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);\r
+                        t.show();\r
+                        return;\r
+                    }\r
                 }\r
     \r
                 Intent i = new Intent(this, FileUploader.class);\r