aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Faulk <wfaulk@webassign.net>2015-04-30 18:48:25 -0400
committerWilliam Faulk <wfaulk@webassign.net>2015-05-04 16:46:15 -0400
commit6383d19dd3921220633686e0e8e78d2d961e0aad (patch)
tree04478cbd91659b82704ca88ca598b516d866b8ec
parentb06e7cd737c9f85c37fb2d17533cc1a2b25715a9 (diff)
downloadopen-keychain-6383d19dd3921220633686e0e8e78d2d961e0aad.tar.gz
open-keychain-6383d19dd3921220633686e0e8e78d2d961e0aad.tar.bz2
open-keychain-6383d19dd3921220633686e0e8e78d2d961e0aad.zip
Wrap EXTRA_REPLACEMENT_EXTRAS section so it only runs on Lollipop or greater
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java86
1 files changed, 44 insertions, 42 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java
index 4141da202..81720d816 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java
@@ -228,48 +228,50 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
// Bluetooth Share will convert text/plain sent via EXTRA_TEXT to HTML
// Add replacement extra to send a text/plain file instead.
- try {
- final File contentFile = new File(getActivity().getExternalCacheDir(),
- "key-" + KeyFormattingUtils.getShortKeyIdAsHexFromFingerprint(fingerprintData, false) +
- ".pgp.asc");
- FileWriter contentFileWriter = new FileWriter(contentFile, false);
- BufferedWriter contentWriter = new BufferedWriter(contentFileWriter);
- contentWriter.write(content);
- contentWriter.close();
- Uri contentUri = Uri.fromFile(contentFile);
-
- final Runnable deleteContentFile = new Runnable() {
- public void run() {
- contentFile.delete();
- }
- };
-
- // delete the file after Bluetooth Share closes the file
- FileObserver tempFileObserver = new FileObserver(contentFile.getAbsolutePath(),
- FileObserver.CLOSE_NOWRITE) {
- @Override
- public void onEvent(int event, String path) {
- // Hopefully it will only be opened and then closed by the share process once
- getContainer().post(deleteContentFile);
- }
- };
- tempFileObserver.startWatching();
-
- // If it's not complete in 1m, the file was not used; delete it
- getContainer().postDelayed(deleteContentFile, 1 * 60 * 1000);
-
- // create replacement extras inside try{}:
- // if file creation fails, just don't add the replacements
- Bundle replacements = new Bundle();
- shareChooser.putExtra(Intent.EXTRA_REPLACEMENT_EXTRAS, replacements);
-
- Bundle bluetoothExtra = new Bundle(sendIntent.getExtras());
- replacements.putBundle("com.android.bluetooth", bluetoothExtra);
-
- bluetoothExtra.putParcelable(Intent.EXTRA_STREAM, contentUri);
- } catch (IOException e) {
- Log.e(Constants.TAG, "error creating temporary Bluetooth key share file!", e);
- Notify.create(getActivity(), R.string.error_bluetooth_file, Notify.Style.ERROR).show();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ try {
+ final File contentFile = new File(getActivity().getExternalCacheDir(),
+ "key-" + KeyFormattingUtils.getShortKeyIdAsHexFromFingerprint(fingerprintData, false) +
+ ".pgp.asc");
+ FileWriter contentFileWriter = new FileWriter(contentFile, false);
+ BufferedWriter contentWriter = new BufferedWriter(contentFileWriter);
+ contentWriter.write(content);
+ contentWriter.close();
+ Uri contentUri = Uri.fromFile(contentFile);
+
+ final Runnable deleteContentFile = new Runnable() {
+ public void run() {
+ contentFile.delete();
+ }
+ };
+
+ // delete the file after Bluetooth Share closes the file
+ FileObserver tempFileObserver = new FileObserver(contentFile.getAbsolutePath(),
+ FileObserver.CLOSE_NOWRITE) {
+ @Override
+ public void onEvent(int event, String path) {
+ // Hopefully it will only be opened and then closed by the share process once
+ getContainer().post(deleteContentFile);
+ }
+ };
+ tempFileObserver.startWatching();
+
+ // If it's not complete in 1m, the file was not used; delete it
+ getContainer().postDelayed(deleteContentFile, 1 * 60 * 1000);
+
+ // create replacement extras inside try{}:
+ // if file creation fails, just don't add the replacements
+ Bundle replacements = new Bundle();
+ shareChooser.putExtra(Intent.EXTRA_REPLACEMENT_EXTRAS, replacements);
+
+ Bundle bluetoothExtra = new Bundle(sendIntent.getExtras());
+ replacements.putBundle("com.android.bluetooth", bluetoothExtra);
+
+ bluetoothExtra.putParcelable(Intent.EXTRA_STREAM, contentUri);
+ } catch (IOException e) {
+ Log.e(Constants.TAG, "error creating temporary Bluetooth key share file!", e);
+ Notify.create(getActivity(), R.string.error_bluetooth_file, Notify.Style.ERROR).show();
+ }
}
startActivity(shareChooser);