I am working on a parse.com Android application, in which I am putting my predefined/default image in ParseFile and sending it to the server. Now I want to put an image on user selection from gallery.
My code is given below:
//It is my default image which i am getting from drawable.
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.usman);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
ParseFile file = new ParseFile("profileImage.png", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a column named "profileImage" and insert the image
Constants.user.put("profileImage", file);
Constants.user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
// dismissLoadingDialog();
if (e == null) {
Toast.makeText(getApplicationContext(),"User Profile Has Been Updated!",Toast.LENGTH_SHORT).show();
} else {
Logs.e(getClass().getName(), e.toString());
Toast.makeText(getApplicationContext(), "Exception/n" + e, Toast.LENGTH_SHORT).show();
// showMessage(e.getMessage());
}
}
});
See Question&Answers more detail:os