【问题标题】:Android: How to wait for the facebook profile picture download?Android:如何等待 facebook 头像下载?
【发布时间】:2013-01-12 14:47:49
【问题描述】:

我的目标是等待个人资料图片下载,以便开始制作使用该图片的视频。

我正在使用提供的 facebook 小部件:ProfilePictureView 来显示图片。

我正在等待 executeMeRequestAsync() 的 onComplete ,但这似乎在等待仅包含图片 ID 的 GraphUser。当我执行 ProfilePictureView 的 setProfileId() 时,它开始下载图片。

有没有可能有类似 onComplete() 等待使用 ProfilePictureView 下载的东西?或者我需要去获取一个位图或其他东西,但是我如何进行回调以报告文件下载已完成?

从 FB 和 onComplete 获取信息的代码会显示我将开始播放视频的按钮

Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
    public void onCompleted(GraphUser user, Response response) {
        showStartButton();                  
    }               
}); 

【问题讨论】:

    标签: android facebook download profile image


    【解决方案1】:

    你也可以这样设置用户头像:

    <com.facebook.widget.ProfilePictureView
    android:id="@+id/friendProfilePicture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:padding="5sp"
    facebook:preset_size="small" />
    

    facebook:preset_size: 小/正常/大/自定义。(根据您的需要) 在代码中设置 facebook 用户 ID:

    ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.friendProfilePicture);
    profilePictureView.setProfileId(userId)`;
    

    【讨论】:

      【解决方案2】:

      为了实现我想要的:在进入下一个屏幕之前下载 facebook 个人资料图片,我在 AsyncTask 的 doInBackground 方法中使用了 loadBitmap 方法 linked by Ming Li

      onComplete 方法如下所示

      public void onCompleted(GraphUser user, Response response) {
          String id = user.getId();
          String url = "http://graph.facebook.com/" + id + "/picture?type=normal";
          ImageLoader il = new ImageLoader(getActivity());//this class extends AsyncTask<String, Integer, Bitmap>
          il.execute(url);
          showStartButton();                  
      }
      

      因此,我通过使用 ProgressDialog 来阻止用户继续操作,当调用 AsyncTask onPostExecute() 方法时,ProgressDialog 将消失,这意味着下载已完成。

      【讨论】:

        【解决方案3】:

        您不需要使用 ProfilePictureView(除非您想将视图对象直接嵌入到动画中,在这种情况下,您应该在 onCompleted 回调中调用 setProfileId)。如果您只想获取个人资料图片,在 onCompleted 中,您可以执行以下操作:

        String id = user.getId();
        Uri uri = Uri.parse("http://graph.facebook.com/" + id + "/picture");
        

        然后使用该 uri 创建位图(请参阅 answers here 了解如何执行此操作)。

        如果你想要不同的尺寸,你也可以在uri中指定一个“type”,或者一个“height”/“width”参数。有关参数值的详细信息,请参阅this page(并搜索“用户的头像”)。

        【讨论】:

        • 这实际上并没有回答我的问题。我正在使用 setProfileId 并且仅当您调用该图像开始下载时。但是你让我明白我的解决方案将使用 Bitmap。感谢您提供的链接!
        猜你喜欢
        • 2017-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多