Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Facebook个人资料图像未显示在android图像视图中_Java_Android_Facebook_Image_Facebook Graph Api - Fatal编程技术网

Java Facebook个人资料图像未显示在android图像视图中

Java Facebook个人资料图像未显示在android图像视图中,java,android,facebook,image,facebook-graph-api,Java,Android,Facebook,Image,Facebook Graph Api,URL1:从facebook获取图像的URL:{fb用户id}/picture?type=large URL2:当URL1被点击时facebook重定向的URL Facebook个人资料图像未显示在图像视图中。这可能是因为url(即从facebook获取图像的url 1)重定向到其他位置以提供图像。当我使用重定向的url(即URL2)直接加载图像时,它工作正常 获取位图的代码: Bitmap b = null; URL url = null; try {

URL1:从facebook获取图像的URL:{fb用户id}/picture?type=large

  • URL2:当URL1被点击时facebook重定向的URL

  • Facebook个人资料图像未显示在图像视图中。这可能是因为url(即从facebook获取图像的url 1)重定向到其他位置以提供图像。当我使用重定向的url(即URL2)直接加载图像时,它工作正常

    获取位图的代码:

        Bitmap b = null;
    
        URL url = null;
        try {
            url = new URL(image_path);
            URLConnection dd = url.openConnection();
                b = BitmapFactory.decodeStream(dd.getInputStream());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    我在谷歌上搜索了很多,我得到了一些关于stackoverflow本身的答案(可能是重复的),但没有得到任何可以解决这个问题的答案。提前谢谢。

    这里-

    当原始协议和重定向协议相同时,自动重定向会自动工作

    这就是原因,您的
    URL2
    工作正常,但没有
    URL1

    因此,如果您尝试从https而不是http加载图像:“”;由于图像的url是“…”,
    BitmapFactory.decodeStream
    将再次工作以获取位图


    希望有帮助。祝你好运。

    通过谷歌搜索,我在这里找到了答案:

    这就解决了我的问题


    HttpURLConnection的follow重定向只是一个指标,事实上它不会帮助您进行“真正的”http重定向,您仍然需要手动处理它。

    您可以使用facebook ProfilePictureView而不是Imageview来实现它

    <com.facebook.login.widget.ProfilePictureView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        facebook:preset_size="small"/>
    
    它起作用了。

    您还可以将ProfilePictureView的大小设置为小/普通/大/自定义

    您好,谢谢您的回复。但问题是,协议只由facebook自动处理。若我使用的是https,那个么自动重定向的url将只在https上。是的,我在我的问题中犯了一个错误,我必须提到URL1和URL2具有相同的协议,并且您已经为此清除了so+1。但是这个问题并没有得到解决。你是说你使用了,但是没有创建图像吗?这是不可能的!我要说的是url()本身没有图像。当我们点击此URL时,我们将被重定向到其他位置以获取图像。这就是我在回答中提到的。谢谢,这就是我已经说过的,带有
    http
    的链接不会获取图像,但是
    https
    会获取图像,因为图像的实际url是
    https
    。不管怎样,如果你头脑清楚的话,就是这样
    ProfilePictureView profilePictureView;
    
    profilePictureView = (ProfilePictureView)findViewById(R.id.friendProfilePicture);
    
    profilePictureView.setProfileId(userId);