【问题标题】:How to retrieve profile picture of linkedin user android如何检索linkedin用户android的个人资料图片
【发布时间】:2016-12-25 16:14:48
【问题描述】:

我尝试通过以下网址获取linkedin用户的头像

http://api.linkedin.com/v1/people/"+userID+"/图片-url

但是我得到了文件未找到异常。

【问题讨论】:

    标签: android linkedin


    【解决方案1】:

    试试这个,希望它对你有用,或者至少让你知道如何去做。 //picUrl 是您的linkedin 联系人图片网址

    BitmapWorkerTask task = new BitmapWorkerTask(picUrl,mContactPic);
    task.execute();
    
    /* Async task to download the image from URL and display it in imageView*/
    class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap>{
    
        /*contact bitmap url */
        private final String mUrl;
    
        /*contact image view*/
        ImageView mView;
        public BitmapWorkerTask(String aUrl, ImageView aView) {
            mUrl = aUrl;
            mView = aView;
        }
    
        @Override
        protected Bitmap doInBackground(String... params) {
    
            if(mBgTaskCancel) {
                /*cancel the execution of this task if the mBgTaskCancel flag is true  */
                this.cancel(false);
            } else {
                /*else get the contact bitmap from the url  */
                final Bitmap bitmap = Utils.getBitmapFromURL(this.mUrl);
                return bitmap;
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(Bitmap aBitmap) {
            if (aBitmap != null) {
                /*set the image bitmap if it is not null */
                mView.setImageBitmap(aBitmap);
            }
        }
    }
    
    
    /**
    * function to download the image from url
    */
    
     public static Bitmap getBitmapFromURL(String aURL) {
        URL lBitmapURL;
        Bitmap lBitmap = null;
        try {
            lBitmapURL = new URL(aURL);
            InputStream lInStream = lBitmapURL.openStream();
            lBitmap = BitmapFactory.decodeStream(lInStream);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        return lBitmap;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多