-->\r
<manifest package="eu.alefzero.owncloud"\r
android:versionCode="1"\r
- android:versionName="0.1.137B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+ android:versionName="0.1.138B" 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
Intent upload_intent = new Intent(context, InstantUploadService.class);
Account account = new Account(account_name, AccountAuthenticator.ACCOUNT_TYPE);
- String mimeType = MimeTypeMap.getSingleton()
- .getMimeTypeFromExtension(
- f.getName().substring(f.getName().lastIndexOf('.') + 1));
+ String mimeType;
+ try {
+ mimeType = MimeTypeMap.getSingleton()
+ .getMimeTypeFromExtension(
+ f.getName().substring(f.getName().lastIndexOf('.') + 1));
+
+ } catch (IndexOutOfBoundsException e) {
+ Log.e(TAG, "Trying to find out MIME type of a file without extension: " + f.getName());
+ mimeType = "application/octet-stream";
+ }
upload_intent.putExtra(InstantUploadService.KEY_ACCOUNT, account);
upload_intent.putExtra(InstantUploadService.KEY_FILE_PATH, file_path);
Log.d(TAG, "Will upload " + mTotalDataToSend + " bytes, with " + mLocalPaths.length + " files");
for (int i = 0; i < mLocalPaths.length; ++i) {
- String mimeType = MimeTypeMap.getSingleton()
- .getMimeTypeFromExtension(
- mLocalPaths[i].substring(mLocalPaths[i]
+
+ String mimeType;
+ try {
+ mimeType = MimeTypeMap.getSingleton()
+ .getMimeTypeFromExtension(
+ mLocalPaths[i].substring(mLocalPaths[i]
.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";
+ }
+
mResult = false;
mCurrentIndexUpload = i;
if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) {
OCFile file = new OCFile(we.path());\r
file.setCreationTimestamp(we.createTimestamp());\r
file.setFileLength(we.contentLength());\r
- \r
- // dvelasco; looks like server is not sending very precise mimeTypes; mp3 file results un application/oct\r
- String filename = file.getFileName();\r
- String mimeType = MimeTypeMap.getSingleton()\r
- .getMimeTypeFromExtension(filename.substring(filename.lastIndexOf('.') + 1));\r
- if (mimeType == null)\r
- file.setMimetype(we.contentType());\r
- else\r
- file.setMimetype(mimeType);\r
- \r
+ file.setMimetype(we.contentType());\r
file.setModificationTimestamp(we.modifiedTimesamp());\r
file.setLastSyncDate(mCurrentSyncTime);\r
return file;\r
import android.view.View;\r
import android.view.View.OnClickListener;\r
import android.view.ViewGroup;\r
+import android.webkit.MimeTypeMap;\r
import android.widget.Button;\r
import android.widget.ImageView;\r
import android.widget.TextView;\r
\r
} catch (Throwable t) {\r
preview.setVisibility(View.INVISIBLE);\r
- Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength());\r
+ Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t);\r
}\r
downloadButton.setText(R.string.filedetails_open);\r
downloadButton.setOnClickListener(new OnClickListener() {\r
@Override\r
public void onClick(View v) {\r
- Intent i = new Intent(Intent.ACTION_VIEW);\r
- i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mFile.getMimetype());\r
- i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
+ String storagePath = mFile.getStoragePath();\r
try {\r
+ Intent i = new Intent(Intent.ACTION_VIEW);\r
+ i.setDataAndType(Uri.parse("file://"+ storagePath), mFile.getMimetype());\r
+ i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
startActivity(i);\r
\r
- } catch (ActivityNotFoundException e) {\r
- Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();\r
+ } catch (Throwable t) {\r
+ Log.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile.getMimetype());\r
+ boolean toastIt = true; \r
+ String mimeType = "";\r
+ 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
+ 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
+ toastIt = false;\r
+ }\r
+ \r
+ } catch (IndexOutOfBoundsException e) {\r
+ Log.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);\r
+ \r
+ } catch (ActivityNotFoundException e) {\r
+ Log.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");\r
+ \r
+ } catch (Throwable th) {\r
+ Log.e(TAG, "Unexpected problem when opening: " + storagePath, th);\r
+ \r
+ } finally {\r
+ if (toastIt) {\r
+ Toast.makeText(getActivity(), "There is no application to handle file " + mFile.getFileName(), Toast.LENGTH_SHORT).show();\r
+ }\r
+ }\r
+ \r
}\r
}\r
});\r
prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
if (prop != null) {
mContentType = (String) prop.getValue();
+ // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
+ if (mContentType.indexOf(";") >= 0) {
+ mContentType = mContentType.substring(0, mContentType.indexOf(";"));
+ }
} else {
mContentType = "DIR";
/*