Guest User

Untitled

a guest
Feb 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. file 1: Image51315.jpg
  2. file 2: Image59192.jpg
  3. ...
  4.  
  5. Drive.DriveApi.requestSync(mGoogleApiClient).await();
  6. Drive.DriveApi.getRootFolder(mGoogleApiClient)
  7. .listChildren(mGoogleApiClient)
  8. .setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
  9. @Override
  10. public void onResult(DriveApi.MetadataBufferResult result) {
  11. if (!result.getStatus().isSuccess()) {
  12. Log.v("DKDK", "Request failed");
  13. return;
  14. }
  15. MetadataBuffer metadataBuffer = result.getMetadataBuffer();
  16.  
  17.  
  18. //Log.e("Resultados",""+metadataBuffer);
  19. Iterator itr = result.getMetadataBuffer().iterator();
  20. while (itr.hasNext()) {
  21. Metadata metadata = (Metadata) itr.next();
  22. mImageName = metadata.getTitle();
  23. Log.e("GDRIVE", "Title " + metadata.getTitle() + " MimeType " + metadata.getMimeType());
  24. FileID = metadata.getDriveId();
  25. Log.e("GDRIVE", "" + FileID);
  26. }
  27. if (metadataBuffer.getCount() == 0) {
  28. Log.e("GDRIVE", "Creando archivo nuevo");
  29. } else {
  30. // FileID = metadataBuffer.get(0).getDriveId();
  31. Log.e("GDRIVE", "Hay Archivos");
  32.  
  33. }
  34. metadataBuffer.release();
  35. }
  36. });
  37.  
  38. private void storeImage(Bitmap image) {
  39. File pictureFile = getOutputMediaFile();
  40. if (pictureFile == null) {
  41. Log.e("FOTO",
  42. "Error creating media file, check storage permissions: ");// e.getMessage());
  43. return;
  44. }
  45. try {
  46. FileOutputStream fos = new FileOutputStream(pictureFile);
  47. image = Bitmap.createScaledBitmap(image, 500, 500, false);
  48. image.compress(Bitmap.CompressFormat.PNG, 100, fos);
  49. fos.close();
  50. } catch (FileNotFoundException e) {
  51. Log.d("FOTO", "File not found: " + e.getMessage());
  52. } catch (IOException e) {
  53. Log.d("FOTO", "Error accessing file: " + e.getMessage());
  54. }
  55. Log.e("FOTO", "PATH>> " + mCurrentPhotoPath);
  56. }
  57.  
  58. /**
  59. * Create a File for saving an image or video
  60. */
  61. private File getOutputMediaFile() {
  62. // To be safe, you should check that the SDCard is mounted
  63. // using Environment.getExternalStorageState() before doing this.
  64. final File mediaStorageDir = new File(Environment.getExternalStorageDirectory()
  65. + "/Android/data/"
  66. + getApplicationContext().getPackageName()
  67. + "/Files");
  68.  
  69. // This location works best if you want the created images to be shared
  70. // between applications and persist after your app has been uninstalled.
  71. // Create the storage directory if it does not exist
  72. if (!mediaStorageDir.exists()) {
  73. if (!mediaStorageDir.mkdirs()) {
  74. return null;
  75. }
  76. }
  77.  
  78.  
  79. Log.e("AFUERAIV", "" + mImageName);
  80. mCurrentPhotoPath = (mediaStorageDir.getPath() + File.separator + mImageName);
  81. mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
  82. return mediaFile;
  83. }
Add Comment
Please, Sign In to add comment