In Android how to get the profile pic of the user that has signed in -


i want profile pic of signed in user.i use following function. user name returned, profile pic in variable micon11 returning null.

string username; bitmap micon11 = null; private void getprofileinformation() {     try {         if (plus.peopleapi.getcurrentperson(mgoogleapiclient) != null) {             person currentperson = plus.peopleapi                     .getcurrentperson(mgoogleapiclient);             username = currentperson.getdisplayname();             string personphotourl = currentperson.getimage().geturl();              try {                 inputstream in = new java.net.url(personphotourl).openstream();                 micon11 = bitmapfactory.decodestream(in);             } catch (exception e) {                 log.e("error", e.getmessage());                 e.printstacktrace();             }          } else {             toast.maketext(getapplicationcontext(),                     "person information null", toast.length_long).show();         }     } catch (exception e) {         e.printstacktrace();     } } 

i setting imageview , textview in screen follows

imageview.setimagebitmap(micon11); textview.settext(username); 

the text getting printed, image null.where did go wrong in code. please me!!

try this:

if (plus.peopleapi.getcurrentperson(mgoogleapiclient) != null) {                 person currentperson = plus.peopleapi.getcurrentperson(mgoogleapiclient);                  string personname = currentperson.getdisplayname();                 string personphoto = currentperson.getimage().geturl();                 system.out.println(personphoto);                 //we can adjust size of image according our requirements: here 200 size of image                 string personimage=personphoto.substring(0,personphoto.lastindexof("=")+1)+"200";                 system.out.println(personimage);              } 

you image of url in personimage string , can load using picasso http://square.github.io/picasso/

picasso.with(context).load(personimage).into(imageview);


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -