diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-02-10 18:46:54 +0100 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2015-02-12 20:23:03 +0000 |
commit | 0f808374af3c71f45b60af3e4040c8e5f12955ac (patch) | |
tree | be0e84d45e6d3a0b30a7d1f60e149ac16f49d00c /android | |
parent | 9e8fa856918e018f8bde4067fdbdbb37e2eaa288 (diff) |
Android: get the file to share in a different thread.
Share feature for cloud files will probably not work properly as it
is, but with this patch we prevent a crash at least.
Change-Id: I95176e9e855a37adf1d3c46edceb0dc6067d9884
Diffstat (limited to 'android')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 065887a3743b..9435c09299a4 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -360,15 +360,42 @@ public class LibreOfficeUIActivity extends LOAbout implements ActionBar.OnNaviga } private void share(int position) { - File file = filePaths.get(position).getDocument(); - Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); - Uri uri = Uri.fromFile(file); - sharingIntent.setType(FileUtilities.getMimeType(file.getName())); - sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri); - sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, - file.getName()); - startActivity(Intent.createChooser(sharingIntent, - getString(R.string.share_via))); + + new AsyncTask<IFile, Void, File>() { + @Override + protected File doInBackground(IFile... document) { + // this operation may imply network access and must be run in + // a different thread + try { + return document[0].getDocument(); + } catch (final RuntimeException e) { + final Activity activity = LibreOfficeUIActivity.this; + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(activity, e.getMessage(), + Toast.LENGTH_SHORT).show(); + } + }); + Log.e(tag, e.getMessage(), e.getCause()); + return null; + } + } + + @Override + protected void onPostExecute(File file) { + if (file != null) { + Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); + Uri uri = Uri.fromFile(file); + sharingIntent.setType(FileUtilities.getMimeType(file.getName())); + sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri); + sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, + file.getName()); + startActivity(Intent.createChooser(sharingIntent, + getString(R.string.share_via))); + } + } + }.execute(filePaths.get(position)); } @Override |