Explorar o código

Avoid crashes when an external app makes a bad response for the selection of a file to upload

David A. Velasco %!s(int64=13) %!d(string=hai) anos
pai
achega
463b30c46a

+ 1 - 1
AndroidManifest.xml

@@ -18,7 +18,7 @@
  -->
  -->
 <manifest package="eu.alefzero.owncloud"
 <manifest package="eu.alefzero.owncloud"
     android:versionCode="1"
     android:versionCode="1"
-    android:versionName="0.1.162B" xmlns:android="http://schemas.android.com/apk/res/android">
+    android:versionName="0.1.163B" xmlns:android="http://schemas.android.com/apk/res/android">
 
 
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />

+ 2 - 0
res/values/strings.xml

@@ -132,4 +132,6 @@
 	<string name="remove_success_msg">"Successful removal"</string>
 	<string name="remove_success_msg">"Successful removal"</string>
 	<string name="remove_fail_msg">"Removal could not be completed"</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>
 </resources>

+ 24 - 14
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

@@ -48,6 +48,7 @@ import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
 import android.widget.ArrayAdapter;
 import android.widget.EditText;
 import android.widget.EditText;
 import android.widget.TextView;
 import android.widget.TextView;
+import android.widget.Toast;
 
 
 import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
 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) {
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (requestCode == ACTION_SELECT_FILE) {
         if (requestCode == ACTION_SELECT_FILE) {
             if (resultCode == RESULT_OK) {
             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);
                 Intent i = new Intent(this, FileUploader.class);