Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook wall stream implementation using graph api in android
    primarykey
    data
    text
    <p>My ImageLoader class--------------------></p> <pre><code> private Bitmap decodeFile(File f){ try { //decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //Find the correct scale value. It should be the power of 2. final int REQUIRED_SIZE=Wall.width; final int REQUIRED_SIZE1=Wall.height; // final int REQUIRED_SIZE=250; // int width_tmp=o.outWidth, height_tmp=o.outHeight; int scale=1; // while(o.outWidth/scale/2&gt;=REQUIRED_SIZE &amp;&amp; o.outHeight/scale/2&gt;=REQUIRED_SIZE) //// scale*=2; while(true){ if((width_tmp/2&lt;REQUIRED_SIZE)||(height_tmp/2&lt;REQUIRED_SIZE1)) break; width_tmp/=2; height_tmp/=2; scale*=2; } //decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f), null, o2); o2.inSampleSize=scale; o2.inJustDecodeBounds = false; // o2.inSampleSize=2; return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) {} return null; } </code></pre> <p>I want to display the facebook wall stream in my application using graph api. </p> <p>The wall stream consists of following things 1)profile picture 2)name ,posted message,posted image 3)Like,Comment options I got the data from facebook graph api <a href="https://graph.facebook.com/me/home?access_token=" rel="nofollow">https://graph.facebook.com/me/home?access_token=</a>"+accesstoken;</p> <p>In this I got data of page1 and I used "paging" to get the data of second page and same for getting third page.</p> <p>But when I tried to display the first page,because of more images I am getting </p> <pre><code>Bitmap size exceeds VM Budget error:Out of Memory error </code></pre> <p>I want to know, how the other facebook applications managing this issue,I observed that they are loading only less number of records at a time.How to do such things,if I got the data in pagewise?</p> <pre><code>public class Wall extends Activity { private Button btnSettings,btnLogout,btnUpdate,btnWall,btnCheckin,btnPubfinder,btnCamera; public String accesstoken,wallres,str_likevariable="",webserv,currentweb; protected static JSONArray jsonArray; JSONObject jsonObject = null; MyProgressDialog dialog; private PullToRefreshListView listView; ArrayList&lt;String&gt; msg=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; name=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; id=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; objid=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; profimg=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; img=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; pic=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; comment=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; likes=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; weburl=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; like_or_unlike=new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; date=new ArrayList&lt;String&gt;(); ImageLoader imageLoader; Handler mHandler; View footerView; private int previousTotal = 0,j=0; public static int width,height; public boolean loading = true,isScrolling,scroll=true,boolisLoad=true,boolDialog=true,addFooter=false; MySimpleArrayAdapter adapter; static { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().permitAll().build()); } //onCreate public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wall); //To get device dimensions android.view.WindowManager w = getWindowManager(); Display d = w.getDefaultDisplay(); width = d.getWidth(); height = d.getHeight(); System.out.println(width); System.out.println(height); btnSettings=(Button)findViewById(R.id.settings); btnLogout=(Button)findViewById(R.id.logout); btnCamera=(Button)findViewById(R.id.camera); btnUpdate=(Button)findViewById(R.id.update); btnWall=(Button)findViewById(R.id.wall); btnCheckin=(Button)findViewById(R.id.checkin); btnPubfinder=(Button)findViewById(R.id.pubfinder); ButtonListener listener=new ButtonListener(); btnSettings.setOnClickListener(listener); btnLogout.setOnClickListener(listener); btnUpdate.setOnClickListener(listener); btnWall.setOnClickListener(listener); btnCheckin.setOnClickListener(listener); btnPubfinder.setOnClickListener(listener); btnCamera.setOnClickListener(listener); //access token accesstoken=Login.mFacebook.getAccessToken(); Log.e("accesstoken",accesstoken); //first page webservice webserv="https://graph.facebook.com/me/home?access_token="+accesstoken; Log.e("firstweb",webserv); //pullToRefresh Listview listView= (PullToRefreshListView ) findViewById(R.id.walldata); listView.setDivider(null); //footer view footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false); // this.mHandler = new Handler(); listView.addFooterView(footerView); // // this.mHandler.postDelayed(m_Runnable,5000); SessionStore.restore(Login.mFacebook, Wall.this); SessionEvents.removeAllAuthListener(); listView.setOnRefreshListener(new OnRefreshListener() { // @Override public void onRefresh() { // Your code to refresh the list contents goes here scroll=true; //to keep the scroll at position where it has hits the load more data pic.clear(); id.clear(); name.clear(); msg.clear(); img.clear(); profimg.clear(); objid.clear(); comment.clear(); weburl.clear(); adapter.clear(); likes.clear(); like_or_unlike.clear(); date.clear(); addFooter=true; // to add the footer view again after removing in pullToRefresh previousTotal = 0; loading = true; listView.removeFooterView(footerView); listView.setAdapter(null); j=0; webserv="https://graph.facebook.com/me/home?access_token="+accesstoken; Log.e("inpull",webserv); System.out.println(listView.getCount()); doInBack dob=new doInBack(); dob.execute(); System.out.println(listView.getCount()); Log.e("hi","doback called"); } }); // listView.setOnScrollListener(new OnScrollListener() { private int threshold = 0; // public void onScrollStateChanged(AbsListView view, int scrollState) { //// if (scrollState != 0) { isScrolling = true; } else { isScrolling = false; //To load the data when the scroll is in offstate adapter.notifyDataSetChanged(); } } public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub if (loading) { if (totalItemCount &gt; previousTotal) { Log.e("in loading","in load"); loading = false; previousTotal = totalItemCount; } } if (!loading &amp;&amp; (firstVisibleItem + visibleItemCount+2) == totalItemCount+1){ System.out.println(firstVisibleItem); System.out.println(visibleItemCount); System.out.println(totalItemCount); scroll=false; Log.v("in gridview loading more","grid load"); // doInBack dob=new doInBack(); dob.execute(); adapter.notifyDataSetChanged(); // doback(webserv); loading = true; } } // } }); doInBack dob=new doInBack(); dob.execute(); // doback(webserv); Log.e("hi","doback called"); } / private class ButtonListener implements View.OnClickListener{ public void onClick(View v) { if(v.equals( btnSettings)){ Intent myintent=new Intent(Wall.this,Settings.class); startActivity(myintent); finish(); } else if(v.equals(btnLogout)){ try { String res=Login.mFacebook.logout(Wall.this); Log.e("response",res); System.out.println(res); System.out.println(Login.mFacebook.isSessionValid()); //if(res.equals("true")) //{ Intent in=new Intent(Wall.this,Login.class); startActivity(in); finish(); //} } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if(v.equals(btnUpdate)){ Update.i=0; Intent myintent=new Intent(Wall.this,Update.class); startActivity(myintent); finish(); } else if(v.equals(btnCamera)){ Intent myintent=new Intent(Wall.this,CameraActivity.class); startActivity(myintent); finish(); } else if(v.equals(btnWall)){ // Intent myintent=new Intent(Wall.this,Wall.class); // startActivity(myintent); // finish(); } else if(v.equals(btnCheckin)){ Intent myintent=new Intent(Wall.this,Checkin.class); startActivity(myintent); finish(); } else if(v.equals(btnPubfinder)){ Intent myintent=new Intent(Wall.this,PubFinder.class); startActivity(myintent); finish(); } } } class doInBack extends AsyncTask&lt;URL, Integer, Long&gt; { protected void onPreExecute() { if(boolDialog){ dialog=MyProgressDialog.show(Wall.this, null,null); } } // currentweb= webserv; @Override protected Long doInBackground(URL... arg0) { currentweb=webserv; // Log.e("hi","doback parsing"); try { // if(urlval&gt;0){ wallres=UrltoValue.getValuefromUrl(currentweb); Log.e("wallrespages",wallres); } JSONObject jobj1=new JSONObject(wallres); JSONObject jobj2=jobj1.getJSONObject("paging"); webserv= jobj2.getString( "next"); jsonArray = jobj1.getJSONArray("data"); for(int i=0;i&lt;jsonArray.length();i++){ jsonObject = jsonArray.getJSONObject(i); if(jsonObject.has("message")||jsonObject.has("picture")) { try{ // msg[j]=jsonObject.getString("message"); if(jsonObject.has("message")) { msg.add(jsonObject.getString("message")); } else{ msg.add(""); } } catch(Exception e){ e.printStackTrace(); } try{ // msg[j]=jsonObject.getString("message"); if(jsonObject.has("picture")) { String firstpicture=jsonObject.getString("picture"); String secondpicture=firstpicture.replaceAll("_s.jpg", "_n.jpg"); Log.e("picurl",secondpicture); pic.add(secondpicture); } else{ pic.add(""); } } catch(Exception e){ e.printStackTrace(); } objid.add(jsonObject.getString("id")); JSONObject jobj=jsonObject.getJSONObject("from"); name.add(jobj.getString("name")); id.add(jobj.getString("id")); if(jsonObject.getString("type").equals("checkin")){ name.set(i,jobj.getString("name")+" "+"is at"+" "+jsonObject.getString("name")); } Log.e("id",id[j]); profimg.add("http://graph.facebook.com/"+id.get(j)+"/picture?type=square"); JSONObject commentjobj=jsonObject.getJSONObject("comments"); comment.add(commentjobj.getString("count")); if(jsonObject.has("likes")) { Log.e("likeornot","likre"); JSONObject likesjobj=jsonObject.getJSONObject("likes"); likes.add(likesjobj.getString("count")); String postid=jsonObject.getString("id"); // graph_or_fql = "fql"; String query = "SELECT likes.user_likes FROM stream WHERE post_id = \'" + postid + "'"; // Log.d("finalThreadID", finalThreadID); Bundle params = new Bundle(); params.putString("method", "fql.query"); params.putString("query", query); // Utility.mAsyncRunner.request(null, params, new LikesListener()); String fqlResponse = Login.mFacebook.request(params); System.out.println(fqlResponse); JSONArray JOLikeresponse=new JSONArray(fqlResponse); if(JOLikeresponse.length()!=0){ JSONObject JOLikeObject = JOLikeresponse.getJSONObject(0); if ( JOLikeObject.has("likes")) { String optlike,optlikesarray; JSONObject optLikes=JOLikeObject; JSONArray optLikesArray; try{ optLikes = JOLikeObject.getJSONObject("likes"); optlike="like"; } catch(Exception e){ optlike="unlike"; } // if(optlike.equals("like")){ if (optLikes.has("user_likes")) { String getUserLikes = optLikes.getString("user_likes"); if (getUserLikes.equals("true")) { like_or_unlike.add("Unlike"); } else if (getUserLikes.equals("false")) { like_or_unlike.add("Like"); } } else { like_or_unlike.add("Like"); } } else { like_or_unlike.add("Like"); } } //if likes object is not there in like response else { like_or_unlike.add("Like"); } } //if the like response Array length is zero else { like_or_unlike.add("Like"); }//FQL query object } //If likes are not there else{ likes.add("0"); like_or_unlike.add("Like"); } weburl.add(currentweb); Log.e("comment", comment.get(j)); String getCreatedTime = jsonObject.getString("created_time"); SimpleDateFormat formatter = getDateFormat(); ParsePosition pos = new ParsePosition(0); long then = formatter.parse(getCreatedTime, pos).getTime(); long now = new Date().getTime(); long seconds = (now - then)/1000; long minutes = seconds/60; long hours = minutes/60; long days = hours/24; String friendly = null; long num = 0; if (days &gt; 0) { num = days; friendly = days + " day"; } else if (hours &gt; 0) { num = hours; friendly = hours + " hour"; } else if (minutes &gt; 0) { num = minutes; friendly = minutes + " minute"; } else if(seconds&gt;0) { num = seconds; friendly = seconds + " second"; } else{ friendly = "few seconds"; } if (num &gt; 1) { friendly += "s"; } String postTimeStamp = friendly.toLowerCase() + " ago"; Log.e("date",postTimeStamp ); date.add(postTimeStamp); j++; } } } catch(Exception e) { e.printStackTrace(); } return null; } protected void onPostExecute(Long result) { try { if(addFooter){ listView.addFooterView(footerView); } addFooter=false; System.out.println(scroll); if(scroll){ adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,comment,objid,weburl,likes, like_or_unlike,date); listView.setAdapter(adapter); listView.postDelayed(new Runnable() { // @Override public void run() { listView.onRefreshComplete(); } }, 2000); if(boolDialog){ dialog.dismiss(); } } else{ // adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,bitmap,comment,objid,weburl); adapter.notifyDataSetChanged(); listView.postDelayed(new Runnable() { // @Override public void run() { listView.onRefreshComplete(); } }, 2000); } if(boolDialog){ dialog.dismiss(); } } catch(Exception e) { e.printStackTrace(); if(boolDialog){ dialog.dismiss(); } } boolDialog=false; } } private static SimpleDateFormat getDateFormat() { return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ"); } public class MySimpleArrayAdapter extends ArrayAdapter&lt;String&gt; { private Activity context; ArrayList&lt;String&gt; namear,msgar,idar,profimage,postimage,commentsnum,objectid,urlString,likescount,like_or_ulike,datesofpost; TextView name1, message1,comments,commentsnumber, likesnumber,likes,dateofpost; ImageView profimg,postimg; ImageLoader imageLoader; Bitmap[] bitdata; // ViewHolder holder ; // View rowView; public MySimpleArrayAdapter(Activity c,int i,ArrayList&lt;String&gt; postpic, ArrayList&lt;String&gt; names,ArrayList&lt;String&gt; msg,ArrayList&lt;String&gt; id,ArrayList&lt;String&gt; proimg,ArrayList&lt;String&gt; comment,ArrayList&lt;String&gt; objid,ArrayList&lt;String&gt; web,ArrayList&lt;String&gt; likecount,ArrayList&lt;String&gt; unlike_or_like,ArrayList&lt;String&gt; dates) { super(c, i, names); Log.e("adapter","adap"); this.context = c; this.namear = names; this.msgar = msg; this.idar = id; this.profimage=proimg; this.postimage=postpic; // this.bitdata=bit; this.commentsnum=comment; this.objectid=objid; this.urlString=web; this.likescount=likecount; this.like_or_ulike=unlike_or_like; this.datesofpost=dates; this.imageLoader = new ImageLoader(context); } // public View getView(final int position, View convertView, ViewGroup parent) { //// View view; // TextView title1,id,name1,dispdate,loc; // ImageView image,delete,arrow; // View view = convertView; //// view = inflater.inflate(R.layout.myfav_row, parent, false); // LayoutInflater inflator = context.getLayoutInflater(); // view = inflator.inflate(R.layout.myfav_row, null); @Override public View getView(final int position, View convertView, ViewGroup parent) { // code to load images View rowView=convertView ; LayoutInflater inflator = getLayoutInflater(); rowView = inflator.inflate(R.layout.walldata, null); name1 = (TextView) rowView.findViewById(R.id.name); message1 = (TextView) rowView.findViewById(R.id.msg); profimg= (ImageView) rowView.findViewById(R.id.profile_pic); postimg= (ImageView) rowView.findViewById(R.id.picpost); comments = (TextView) rowView.findViewById(R.id.comment); likes = (TextView) rowView.findViewById(R.id.like); commentsnumber = (TextView) rowView.findViewById(R.id.commentnumber); likesnumber = (TextView) rowView.findViewById(R.id.likesnumber); dateofpost = (TextView) rowView.findViewById(R.id.datepost); // rowView.setTag(holder); Log.e("user",idar.get(position)); Log.e("adapter","adap"); name1.setText(namear.get(position)); if(msgar.get(position)!=""){ message1.setText(msgar.get(position)); } else { message1.setVisibility(View.GONE); } if(!isScrolling){ if(!postimage.get(position).equals("")) {try{ imageLoader.DisplayImage(postimage.get(position).replace(" ", "%20"), postimg) ; // Bitmap b= imageLoader.getBitmap(postimage.get(position)); // postimg.setImageBitmap(b); } catch(Exception e){ e.printStackTrace(); } } else { postimg.setVisibility(View.GONE); } } try{ imageLoader.DisplayImage(profimage.get(position).replace(" ", "%20"), profimg) ; } catch(Exception e){ e.printStackTrace(); } dateofpost.setText(datesofpost.get(position)); commentsnumber.setText(commentsnum.get(position)); likesnumber.setText(likescount.get(position)); likes.setText(like_or_ulike.get(position)); likes.setOnClickListener(new OnClickListener() { public void onClick(View v) { // if(likes.getText().toString().equals("Like")){ TextView t=(TextView)v; TextView likescountmodify = null; View parent = (View) t.getParent(); if (parent != null) { likescountmodify = (TextView)parent.findViewById(R.id.likesnumber); } int i= Integer.parseInt(likescount.get(position)); if(like_or_ulike.get(position).equals("Like")){ Log.e("inlike","like"); like_or_ulike.set(position, "Unlike"); t.setText(like_or_ulike.get(position)); UrltoValue.getValuefromUrl("https://graph.facebook.com/"+objectid.get(position)+"/likes?access_token="+accesstoken+"&amp;method="+"post"); // listView.getAdapter().getItemAt(position); j=i+1; String s=Integer.toString(j); likescount.set(position, s); likescountmodify.setText(likescount.get(position)); } else{ Log.e("unlike","unlike"); like_or_ulike.set(position, "Like"); t.setText(like_or_ulike.get(position)); UrltoValue.getValuefromUrl("https://graph.facebook.com/"+objectid.get(position)+"/likes?access_token="+accesstoken+"&amp;method="+"DELETE"); j=i-1; String s=Integer.toString(j); likescount.set(position, s); likescountmodify.setText(likescount.get(position)); } } }); comments.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent myintent=new Intent(Wall.this,Comments.class); myintent.putExtra("name", namear.get(position)); myintent.putExtra("profimg", profimage.get(position)); myintent.putExtra("message", msgar.get(position)); myintent.putExtra("postpic", postimage.get(position)); myintent.putExtra("objectid", objectid.get(position)); myintent.putExtra("commentsnum",commentsnum.get(position)); myintent.putExtra("webservice", urlString.get(position)); startActivity(myintent); finish(); } }); return rowView; } } </code></pre> <p>please help</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload