Newline没有在Facebook上分享字符串

时间:2013-07-02 13:25:59

标签: android facebook sharing

我有一个包含两个字符串的对象MyObject

public class MyObject{ 

    String title
    String description
}

我想在以下平台(SMS,EMail,Facebook)上分享此对象

所以我的代码是

public String getMySharingStringViaSMS(){

    return title + "\r\n" + description
}

public String getMySharingStringViaEMAIL(){

    return title + "<br />" + description
}

现在问题是(\ r \ n)和(br)都无法在Facebook上运行

任何人都可以提供帮助,我怎样才能只制作一个处理所有人的方法

1 个答案:

答案 0 :(得分:0)

在Facebook上分享一些需要实施FacebookSdk 3.0的东西,请遵循以下教程: http://www.kpbird.com/2013/03/android-login-using-facebook-sdk-30.html

主要目标是通过Facebook提供“登录”以分享墙上的内容。 登录后,请尝试以下方法:

private void publishStory(String hash, String title, String user) {

Session session = Session.getActiveSession();

if (session != null){
    // Check for publish permissions    
    List<String> permissions = session.getPermissions();
    if (!isSubsetOf(PERMISSIONS, permissions)) {
        pendingPublishReauthorization = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session
                .NewPermissionsRequest(getActivity(), PERMISSIONS);
        session.requestNewPublishPermissions(newPermissionsRequest);
        return;
    }
    Bundle postParams = new Bundle();
    postParams.putString("name", title);
    postParams.putString("caption", "By Recommend Android");
    postParams.putString("description", user+" "+"STRONGLY recommends"+" "+title);
    postParams.putString("link", "http://re.co/"+hash);
    postParams.putString("picture", "http://re.co/assets/img/useful-exp.png");

    Request.Callback callback= new Request.Callback() {
        public void onCompleted(Response response) {
            JSONObject graphResponse = response
                    .getGraphObject()
                    .getInnerJSONObject();
            String postId = null;
            try {
                postId = graphResponse.getString("id");
            } catch (JSONException e) {
                Log.i(TAG,
                        "JSON error "+ e.getMessage());
            }

不要忘记你的Html标签必须在strings.xml中声明,如下所示:

<string name="demoStr"><Data><![CDATA[ <b>ABC</b><br /> something ]]> </Data></string>

然后getString()将获得"<b>ABC</b><br />something"