2014-03-05 57 views
1

我模仿我的代碼,他們Mealspotting教程後,但由於某些原因,我無法看到保存在數據瀏覽器中的文件。這是爲什麼?這裏是我的代碼:Parse.com文件保存的Android不工作

private void saveScaledPhoto(byte[] data) { 

     // Resize photo from camera byte array 
     Bitmap snypImage = BitmapFactory.decodeByteArray(data, 0, data.length); 
     Bitmap snypImageScaled = Bitmap.createScaledBitmap(snypImage, 200, 200 
       * snypImage.getHeight()/snypImage.getWidth(), false); 

     // Override Android default landscape orientation and save portrait 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(90); 
     Bitmap rotatedScaledMealImage = Bitmap.createBitmap(snypImageScaled, 0, 
       0, snypImageScaled.getWidth(), snypImageScaled.getHeight(), 
       matrix, true); 

     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     rotatedScaledMealImage.compress(Bitmap.CompressFormat.JPEG, 100, bos); 

     byte[] scaledData = bos.toByteArray(); 

     // Save the scaled image to Parse 
     photoFile = new ParseFile("snyp.jpg", scaledData); 
     photoFile.saveInBackground(new SaveCallback() { 

      public void done(ParseException e) { 
       if (e == null) { 
        ParseUser.getCurrentUser().put("photo",photoFile); 
        Log.d("save status",photoFile.getName() + " is saved!"); 
       } else { 

        Toast.makeText(getActivity(), 
          "Error saving: " + e.getMessage(), 
          Toast.LENGTH_LONG).show(); 
       } 
      } 
     }); 
    } 
+0

這不是在文件存儲或者 – shreyashirday

+0

你是如何保存圖像文件?你能發佈代碼嗎? – yushulx

+0

「 ParseUser.getCurrentUser()把(」照片」,photoFile); – shreyashirday

回答

1

你只是忘記保存您的用戶對象:ParseUser.getCurrentUser().saveEventually();

+0

爲什麼會saveEventually(),而不是saveInBackground()? – shreyashirday

+0

還,我還可以檢索用戶的文件,而無需創建一個照片級? – shreyashirday

+0

只是因爲它更簡單。saveEventually將節省您的照片,最終(只要它可以):) –