无法从当前用户检索查询 - 解析(Android版) [英] Cannot Retrieve Query from Current User - Parse (Android)

查看:214
本文介绍了无法从当前用户检索查询 - 解析(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从当前用户检索图像显示为资料图片。

我可以很容易地得到它后插入一个特定的对象ID query.getInBackground()我想要做的是拉的profilePicture工作用户当前登录,因此当前用户,而不是一个特定的用户。我该如何解决这个问题?

  progressDialog = ProgressDialog.show(GalleryActivity.this,,
                下载图片...,真正的);        //找到名为ImageUpload之类的表中Parse.com
        ParseQuery< ParseUser>查询= ParseUser.getQuery();        //从类找到O​​BJECTID        ParseUser的currentUser = ParseUser.getCurrentUser();
        query.getInBackground(将String.valueOf(ParseUser.getCurrentUser()),
                新GetCallback< ParseUser>(){                    公共无效完成(ParseUser对象,
                                     ParseException的E){
                        // TODO自动生成方法存根                        //找到名为ImageName,并设置列
                        //字符串
                        ParseFile的FileObject =(ParseFile)对象
                                获得(profilePicture);
                        文件对象
                                .getDataInBackground(新GetDataCallback(){                                    公共无效完成(字节[]数据,
                                                     ParseException的E){
                                        如果(E == NULL){
                                            Log.d(测试,
                                                    我们已经得到了数据的数据。);
                                            //德code中的字节[]进入
                                            //位图
                                            BMP位图= BitmapFactory
                                                    由Matchi.com提供回到codeByteArray的(
                                                            数据,0,
                                                            data.length);                                            //从ImageView的
                                            // main.xml中
                                            ImageView的图像=(ImageView的)findViewById(R.id.galleryProfilePic);                                            //将位图到
                                            // ImageView的                                            位图大小= Bitmap.createScaledBitmap(BMP,300,300,TRUE);
                                            位图conv_bm = getRoundedRectBitmap(调整大小,300);                                            image.setImageBitmap(conv_bm);                                            //关闭进度对话框
                                            progressDialog.dismiss();                                        }其他{
                                            Log.d(测试,
                                                    有下载的数据的问题。);
                                            ImageView的图像=(ImageView的)findViewById(R.id.galleryProfilePic);
                                            image.setImageResource(R.drawable.ic_default_profile_picture);
                                        }
                                    }
                                });
                    }
                });


解决方案

我居然通过将当前用户的对象ID作为字符串到查询取代静态对象ID得到了这个工作:

 字符串的currentUser = ParseUser.getCurrentUser()getObjectId()。
query.getInBackground(的currentUser,
        新GetCallback< ParseUser>(){

I'm trying to retrieve an image from the current user to display as a profile picture.

I can quite easily get it to work by inserting a specific object ID after query.getInBackground() What I want to do is to pull the "profilePicture" of the user currently logged in, hence current User, and not just one specific user. How can I fix this?

        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);
                                        }
                                    }
                                });
                    }
                });

解决方案

I actually got this working by passing the object ID of the current user as a string into the query to replace the static object ID:

String currentUser = ParseUser.getCurrentUser().getObjectId();
query.getInBackground(currentUser,
        new GetCallback<ParseUser>() {

这篇关于无法从当前用户检索查询 - 解析(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆