Facebook sdk android wall post line break

I am making an application that posts some information on your facebook wall using facebook sdk for Android. This works, but I cannot get new lines on messages. I tried \n, but it is 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());  

Thank,

James ford

+5
source share
5 answers

Hi James, I have tried this before, even with html code, but I think it is not possible. The reason Facebook must have control in order to avoid empty spaces or line breaks in its posts.

+1
source

(, , , , - facebook).

+1

JSON Facebook.  ?

: -

1: - , JSON TEXTVIEW.

2: - , , :) textview          GetText().ToString

3: - facebook.

4: - , , ,          . u ,

5: -

tv.setVisibility(View.GONE)

facebook.. facebook textview , : D

...

I place it at the click of a button

1)

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

2) add a 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) message sending method

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 THAT HELP :)

0
source

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());
0
source

It works:

Use this: <center></center>

Instead of br or newline, etc. You can only do one in a row (i.e. you cannot increase the interval).

-1
source

All Articles