我试图从当前用户检索图像以显示为个人资料图片。
我可以通过在query.getInBackground()
之后插入特定的对象ID轻松地使其工作。我想要做的是拉出" profilePicture"当前用户的当前用户,而不仅仅是一个特定用户。我该如何解决这个问题?
progressDialog = ProgressDialog.show(GalleryActivity.this, "",
"Downloading Image...", true);
// Locate the class table named "ImageUpload" in Parse.com
ParseQuery<ParseUser> query = ParseUser.getQuery();
// Locate the objectId from the class
ParseUser currentUser = ParseUser.getCurrentUser();
query.getInBackground(String.valueOf(ParseUser.getCurrentUser()),
new GetCallback<ParseUser>() {
public void done(ParseUser object,
ParseException e) {
// TODO Auto-generated method stub
// Locate the column named "ImageName" and set
// the string
ParseFile fileObject = (ParseFile) object
.get("profilePicture");
fileObject
.getDataInBackground(new GetDataCallback() {
public void done(byte[] data,
ParseException e) {
if (e == null) {
Log.d("test",
"We've got data in data.");
// Decode the Byte[] into
// Bitmap
Bitmap bmp = BitmapFactory
.decodeByteArray(
data, 0,
data.length);
// Get the ImageView from
// main.xml
ImageView image = (ImageView) findViewById(R.id.galleryProfilePic);
// Set the Bitmap into the
// ImageView
Bitmap resized = Bitmap.createScaledBitmap(bmp, 300, 300, true);
Bitmap conv_bm = getRoundedRectBitmap(resized, 300);
image.setImageBitmap(conv_bm);
// Close progress dialog
progressDialog.dismiss();
} else {
Log.d("test",
"There was a problem downloading the data.");
ImageView image = (ImageView) findViewById(R.id.galleryProfilePic);
image.setImageResource(R.drawable.ic_default_profile_picture);
}
}
});
}
});
答案 0 :(得分:0)
我实际上通过将当前用户的对象ID作为字符串传递给查询来替换静态对象ID来实现此目的:
String currentUser = ParseUser.getCurrentUser().getObjectId();
query.getInBackground(currentUser,
new GetCallback<ParseUser>() {