开发者

facebook sdk android wall post line break

I'm making an application that is posting some info开发者_高级运维rmation to your facebook wall using facebook sdk for android. This works, but I can't seem to get new lines on the posts. I have tried \n but it doesent work. Any suggestions?

Here is my code:

Bundle parameters = new Bundle();

String temp = "";
for (int i = 0; i < mArrayAdapter.getCount(); i++){
            temp = temp + mArrayAdapter.getItem(i) + "\n"; // Not working
}

parameters.putString("message", temp);
mFacebook.dialog(this, "stream.publish", parameters, new DialogListener());  

Thanks,

James Ford


Hi James i have tried that before, even with html code but i think thats not possible. The reason, Facebook must have a control to avoid blank spaces or line break on his posts.


New lines are not allowed in stream posts (the fact that you may have seen them in the past are bugs on facebook).


make use of JSON to post on facebook.. how? look here

STEPS :-

Step 1 :- At this link u will came to know how to use JSON for setting text to TEXTVIEW.

Step 2 :- May be this is not u r looking for :) assign the text of textview to some string using GetText().ToString

Step 3 :- use this string to post to the facebook.

Step 4 :- I did the same after spending lot of time in googling and finally got the result by using this trick. u can see my post that i posted during test here

Step 5 :- set the visibilty of this text box to gone using

tv.setVisibility(View.GONE)

And u r done with your posting to facebook.. let the facebook and textview handle how they manage spaces and new line character :D

Some Coding work for newbies like me...

I am posting it on click of button

1)

 tv= (TextView)findViewById(R.id.tv);
 click=(Button)findViewById(R.id.btn1);
    click.setOnClickListener(mthdpost);

2) add on click event to this button

   private View.OnClickListener mthdpost=new View.OnClickListener() {

        @Override
        public void onClick(View v) {
try {
                String json = "{"

                    + "  \"name\": \"myName\", "

                    + "  \"message\": [\"myMessage1\",\"myMessage2\"],"

                    + "  \"place\": \"myPlace\", "

                    + "  \"date\": \"thisDate\" "

                    + "}";

                /* Create a JSON object and parse the required values */

                JSONObject object = (JSONObject) new JSONTokener(json).nextValue();

                String name = object.getString("name");

                String place = object.getString("place");

                String date = object.getString("date");

                JSONArray message = object.getJSONArray("message");

                String MessageToPost= null;
                tv.setText("Name: "+ name +"\n\n");

                tv.append("Place: "+ place +"\n\n");

                tv.append("Date: "+ date +"\n\n");



                /*JSONObject attachment = new JSONObject();

                attachment.put("Name: ","\n\n");

                attachment.put("Place: ","\n\n");

                attachment.put("Date: ","\n\n");*/

                for(int i=0;i<message.length();i++)

                {

                    tv.append("Message: "+ message.getString(i) +"\n\n");
                    //attachment.put("Message: ","\n\n");

                }
                MessageToPost=tv.getText().toString();
                postToWall(MessageToPost);// called the method having logic to post on wall and sending the textview text to to post as message

                } catch (JSONException e)
                {e.printStackTrace();
                }

                catch(Exception ex)
                {ex.printStackTrace();}

                }


        };

3) method for posting the message

public void postToWall(String msg){


        Log.d("Tests", "Testing graph API wall post");
        try {
               String response = facebook.request("me");
               Bundle parameters = new Bundle();
               //parameters.putString("message", msg.toString());
               parameters.putString("message", msg);
               parameters.putString("description", "test test test");
               response = facebook.request("me/feed", parameters, 
                       "POST");
               Log.d("Tests", "got response: " + response);
               if (response == null || response.equals("") || 
                       response.equals("false")) {
                  Log.v("Error", "Blank response");
               }
        } catch(Exception e) {
            e.printStackTrace();
        }

        }

HOPE IT WILL HELP :)


This worked for me:

StringBuilder messageData = new StringBuilder(title).append('\n')
    .append('\n').append(message).append('\n').append('\n')
    .append(description);
// Message
postParams.putString("message", messageData.toString());


This works:

Use this: <center></center>

Instead of a br or a newline, etc. You can only do one in a row (ie. you can't increase the spacing).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜