(Intent data)
| 482 | } |
| 483 | |
| 484 | private void save(Intent data) { |
| 485 | long id = getIntent().getLongExtra("id", -1L); |
| 486 | |
| 487 | Bundle args = new Bundle(); |
| 488 | args.putLong("id", id); |
| 489 | args.putParcelable("uri", data.getData()); |
| 490 | |
| 491 | new SimpleTask<Void>() { |
| 492 | private Toast toast = null; |
| 493 | |
| 494 | @Override |
| 495 | protected void onPreExecute(Bundle args) { |
| 496 | toast = ToastEx.makeText(ActivityCode.this, R.string.title_executing, Toast.LENGTH_LONG); |
| 497 | toast.show(); |
| 498 | } |
| 499 | |
| 500 | @Override |
| 501 | protected void onPostExecute(Bundle args) { |
| 502 | if (toast != null) |
| 503 | toast.cancel(); |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | protected Void onExecute(Context context, Bundle args) throws Throwable { |
| 508 | long id = args.getLong("id"); |
| 509 | Uri uri = args.getParcelable("uri"); |
| 510 | |
| 511 | if (uri == null) |
| 512 | throw new FileNotFoundException(); |
| 513 | |
| 514 | if (!"content".equals(uri.getScheme())) { |
| 515 | Log.w("Export uri=" + uri); |
| 516 | throw new IllegalArgumentException(uri.getScheme()); |
| 517 | } |
| 518 | |
| 519 | DB db = DB.getInstance(context); |
| 520 | EntityMessage message = db.message().getMessage(id); |
| 521 | if (message == null) |
| 522 | return null; |
| 523 | |
| 524 | File file = message.getFile(context); |
| 525 | |
| 526 | ContentResolver resolver = context.getContentResolver(); |
| 527 | try (OutputStream os = resolver.openOutputStream(uri)) { |
| 528 | try (InputStream is = new FileInputStream(file)) { |
| 529 | Helper.copy(is, os); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | return null; |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | protected void onExecuted(Bundle args, Void data) { |
| 538 | ToastEx.makeText(ActivityCode.this, R.string.title_completed, Toast.LENGTH_LONG).show(); |
| 539 | } |
| 540 | |
| 541 | @Override |
no test coverage detected