android - Setting facebook's profile picture as a LinearLayout background -


i have been trying no avail set facebooks profile picture linearlayout background in application. here 2 ways tried this:

first way: got uri profile picture , converted drawable

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_profile);     linearlayout banner = (linearlayout)findviewbyid(r.id.banner);        profile profile = profile.getcurrentprofile();         if(profile != null){            // profile_pic_id.setprofileid((profile.getid()));             drawable d;             uri uri = profile.getlinkuri();             //also tried profile.getprofilepictureuri(random_num,random_num)             try {                  inputstream inputstream = getcontentresolver().openinputstream(uri);                  d = drawable.createfromstream(inputstream, uri.tostring());             } catch (filenotfoundexception e) {                 d = getresources().getdrawable(r.drawable.blue_material);             }             banner.setbackgrounddrawable(d);         } } 

now threw exception drawable blue_material 1 (the drawable set in catch block), if knows why throwing exception time i'd grateful.

second way: converted profilepictureview imageview , used getdrawable() on imageview.

 profilepictureview profilepicturefb=(profilepictureview)findviewbyid(r.id.pic);  profilepicturefb.setprofileid((profile.getid()));  imageview fbimage = ( ( imageview)profilepicturefb.getchildat( 0));  banner.setbackgrounddrawable(fbimage.getdrawable()); 

now resulted in having background default picture facebook puts when has no profile pic.

and whenever use decodestream exception gets thrown.(example below)

url img_url =new url("https://graph.facebook.com/"+profile.getid()+"/picture?type=normal");                 bitmap bmp =bitmapfactory.decodestream(img_url.openconnection().getinputstream());//bmp bitmap 

i didnt want resort asking question on stackoverflow because wanted solve myself, tried long, had help.

thanks answers :)

i solved it!!

i used imageloader, , reason url works it, here code:

        imageview = (imageview) findviewbyid(r.id.pic);         imageview.setscaletype(imageview.scaletype.fit_xy);         imageloader = imageloader.getinstance();          profile profile = profile.getcurrentprofile();         if(profile != null){                        displayimageoptions options = new displayimageoptions.builder().cacheinmemory(true).cacheondisk(true).build();             imageloader.displayimage("http://graph.facebook.com/" + profile.getid() + "/picture?width=400&height=400", imageview, options);            // banner.setbackgrounddrawable(imageview.getdrawable());             imageview.setscaletype(imageview.scaletype.fit_xy); 

the method setscaletype stretches imageview across mylinearlayout. more information universal image loader visit link: https://github.com/nostra13/android-universal-image-loader


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -