LizG LizG - 5 months ago 28
Android Question

Retrieving an image file from parse.com and displaying in an image view

I am trying to download the image from parse.com and display in a image view in an Activity extending AppCompatActivity.

I got this code from one of many searches:

ParseImageView mImage = (ParseImageView) findViewById(R.id.image);

ParseObject object = new ParseObject("Appetizers"); // class name
ParseFile postImage = object.getParseFile("imageFiles"); // column name
String imageUrl = postImage.getUrl() ;//live url
Uri imageUri = Uri.parse(imageUrl);

Picasso.with(getBaseContext()).load(imageUri.toString()).into(mImage);


My parse class

Any help would be appreciated.

File format: jpg

Answer

I figured it out by debugging and setting logs everywhere ...

In the sending class:

ParseObject po = mAppetizers.get(position); // get position
String ID = po.getObjectId().toString();

Intent intent = new Intent(Appetizer.this, AppetizerRecipe.class);

intent.putExtra("ID", ID);
startActivity(intent);

In the receiver's class:

final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);
String ID = getIntent().getStringExtra("ID");

        ParseQuery<ParseObject> getimage = new ParseQuery<>("Appetizers");
    getimage.addAscendingOrder("appetizer");
    getimage.whereEqualTo("ID", ID);
        Log.d("AppetizerRecipe2", "object: " + ID);
    getimage.getInBackground(ID, new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                Log.v("what is e?", "e = " + e);
                // success
                final ParseFile fileObject = (ParseFile)object.get("imageFiles");
                fileObject.getDataInBackground(new GetDataCallback() {
                    public void done(byte[] data, ParseException e) {
                        if (e == null) {
                            Log.d("test", "We've got data in data.");
                            // use data for something
                            Log.d("test", "Get your image..." + fileObject.getUrl());
                    Picasso.with(getBaseContext()).load(fileObject.getUrl()).placeholder
                            (R.drawable.ic_launcher).into(mImage);

                        } else {
                            Log.d("test", "There was a problem downloading the data.");
                        }
                    }
                });

            } else {
                // fail
                Log.d("test", "Error Message..." + e.getMessage());
            }
        }
    });