Fixing null pointers when finding out MIME types from extensions
authorDavid A. Velasco <dvelasco@solidgear.es>
Thu, 5 Jul 2012 14:38:59 +0000 (16:38 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Thu, 5 Jul 2012 14:38:59 +0000 (16:38 +0200)
AndroidManifest.xml
src/eu/alefzero/owncloud/files/PhotoTakenBroadcastReceiver.java
src/eu/alefzero/owncloud/files/services/FileUploader.java
src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

index c656db4..281844b 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.147B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.148B" 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 9314942..c89a825 100644 (file)
@@ -111,7 +111,7 @@ public class PhotoTakenBroadcastReceiver extends BroadcastReceiver {
                         Intent upload_intent = new Intent(context, InstantUploadService.class);
                         Account account = new Account(account_name, AccountAuthenticator.ACCOUNT_TYPE);
                         
-                        String mimeType;
+                        String mimeType = null;
                         try {
                             mimeType = MimeTypeMap.getSingleton()
                                     .getMimeTypeFromExtension(
@@ -119,8 +119,9 @@ public class PhotoTakenBroadcastReceiver extends BroadcastReceiver {
                         
                         } catch (IndexOutOfBoundsException e) {
                             Log.e(TAG, "Trying to find out MIME type of a file without extension: " + f.getName());
-                            mimeType = "application/octet-stream";
                         }
+                        if (mimeType == null)
+                            mimeType = "application/octet-stream";
                         
                         upload_intent.putExtra(InstantUploadService.KEY_ACCOUNT, account);
                         upload_intent.putExtra(InstantUploadService.KEY_FILE_PATH, file_path);
index 68ddafb..71c4258 100644 (file)
@@ -158,7 +158,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         
         for (int i = 0; i < mLocalPaths.length; ++i) {
             
-            String mimeType;
+            String mimeType = null;
             try {
                 mimeType = MimeTypeMap.getSingleton()
                         .getMimeTypeFromExtension(
@@ -166,8 +166,9 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
                                     .lastIndexOf('.') + 1));
             } catch (IndexOutOfBoundsException e) {
                 Log.e(TAG, "Trying to find out MIME type of a file without extension: " + mLocalPaths[i]);
-                mimeType = "application/octet-stream";
             }
+            if (mimeType == null)
+                mimeType = "application/octet-stream";
             
             mCurrentIndexUpload = i;
             if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) {
index 533809f..505ff6c 100644 (file)
@@ -280,7 +280,7 @@ public class FileDetailFragment extends SherlockFragment implements
                             try {\r
                                 Intent i = new Intent(Intent.ACTION_VIEW);\r
                                 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));\r
-                                if (mimeType != mFile.getMimetype()) {\r
+                                if (mimeType != null && !mimeType.equals(mFile.getMimetype())) {\r
                                     i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType);\r
                                     i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
                                     startActivity(i);\r