Guest User

Untitled

a guest
Jan 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  2. getContentResolver().takePersistableUriPermission(data.getData(),
  3. Intent.FLAG_GRANT_READ_URI_PERMISSION |
  4. Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  5. }
  6.  
  7. try {
  8. countDownLatch = new CountDownLatch(1);
  9. new Thread(new Runnable() {
  10. @Override
  11. public void run() {
  12. try {
  13. Thread.sleep(300);
  14. } catch (InterruptedException e) {
  15. e.printStackTrace();
  16. }
  17. countDownLatch.countDown();
  18. }
  19. }).start();
  20.  
  21. countDownLatch.await();
  22.  
  23. } catch (InterruptedException e) {
  24. e.printStackTrace();
  25. }
  26. target_filename= String.valueOf(System.currentTimeMillis());
  27. treeUri = data.getData();
  28. DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
  29.  
  30. // Create a new file and write into it
  31. newFile = pickedDir.createFile("text", target_filename);
  32. for(int i=0;i<10;i++){
  33. newFile=pickedDir.findFile(target_filename);
  34. int wait_sd=0;
  35. countDownLatch = new CountDownLatch(1);
  36. do{
  37. if(newFile.canWrite()){
  38. wait_sd=10;
  39. }else{
  40. try {
  41. countDownLatch.await(500, TimeUnit.MILLISECONDS);
  42. wait_sd++;
  43. } catch (InterruptedException e) {
  44. // TODO 自動生成された catch ブロック
  45. e.printStackTrace();
  46. }
  47. }
  48. }while(wait_sd<10);
  49.  
  50. }
Add Comment
Please, Sign In to add comment