how to get file from parse.com in android?

家住魔仙堡 提交于 2019-12-24 18:55:09

问题


here is my db structure of purchased_item

and here is my image table

i want to get file FFNglxekCv

ParseQuery<ParseObject> query = ParseQuery.getQuery(KEY_MASTER_PURCHASED_ITEM);
    ParseUser currentUser = ParseUser.getCurrentUser();


    user.setObjectId(currentUser.getObjectId());*/

    query.whereEqualTo(KEY_PURCHASED_BY, currentUser);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> parseObjectList, ParseException e) {
            hideProgressDialog();
            if (e == null) {

                if (!parseObjectList.isEmpty()) {

                    for (int i = 0; i < parseObjectList.size(); i++) {

                        ParseObject parseObject = parseObjectList.get(i);

                     // ParseFile parseFile =(ParseFile) parseObject.getParseFile("image");


                        Log.e(TAG,TAG);
                    }
                }

            } else {
                if (!e.getLocalizedMessage().equalsIgnoreCase(""))
                    showErrorToast(e.getLocalizedMessage(), true);
                else
                    showErrorToast(getString(R.string.no_response_from_server), true);
                Log.d(TAG, "Error: " + e.getMessage());
            }
        }
    });

i dont know how to get image from parse.com


回答1:


I'm using Back4App! Could you please try something like the below?

ParseQuery<ParseObject> query = ParseQuery.getQuery("Photo");
        query.whereEqualTo("objectId", FFNglxekCv);
        query.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {
                if(e==null){
                    for(ParseObject object : objects){
                        ParseFile file = (ParseFile) object.get("image");
                        file.getDataInBackground(new GetDataCallback() {
                            @Override
                            public void done(byte[] data, ParseException e) {
                                if(e==null){
                                    Bitmap bitmapImage = BitmapFactory.decodeByteArray(data, 0, data.length);
                                    ImageView image = new ImageView(getApplicationContext());
                                    image.setImageBitmap(bitmapImage);
                                    relativeLayout.addView(image);
                                }
                                else{
                                    Log.i("info", e.getMessage());
                                }
                            }
                        });
                    }
                }
                else{
                    Log.i("info", e.getMessage());
                }
            }
        });

Let I kow if it's working for you!



来源:https://stackoverflow.com/questions/51874166/how-to-get-file-from-parse-com-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!