Android Fabric Twitter Share Listener

I am using Fabric SDK to send tweets from my application.

I am creating a share dialog and posting a tweet from an activity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TwitterAuthConfig authConfig = new TwitterAuthConfig(CONSUMER_KEY, CONSUMER_SECRET);
    Fabric.with(this, new TwitterCore(authConfig), new TweetComposer());

    Bundle bundle = getIntent().getExtras().getBundle(SHARE_DATA);
    String description = bundle.getString(SHARE_DESCRIPTION);
    String title = bundle.getString(SHARE_TITLE);
    String picture = bundle.getString(SHARE_PICTURE_LINK);
    String link = bundle.getString(SHARE_LINK);

    TweetComposer.Builder builder = null;
    try {
        InputStream in = new java.net.URL(picture).openStream();
        Bitmap bitmap = BitmapFactory.decodeStream(in);
        Uri yourUri = getImageUri(this,bitmap);
        builder = new TweetComposer.Builder(this)
                .text(title + "\n" + description)
                .url(new URL(link))
                .image(yourUri);
        //??? IS THERE ANY LISTENER ???
        builder.show();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}

      

I want to know the status of the sharing like success or not , but I cannot find a listener for this action.

Did I miss something?

+3


source to share


2 answers


Instead of using builder.show (), you should use builder.createIntent ():

Intent intent = new TweetComposer.Builder(getActivity())
        .text("TEXT")
        .url("URL")
        .createIntent();

startActivityForResult(intent, TWEET_COMPOSER_REQUEST_CODE);

      



To get feedback of the result in onActivityResult ():

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == TWEET_COMPOSER_REQUEST_CODE) {

        if(resultCode == Activity.RESULT_OK) {

            onTwitterSuccess();

        } else if(resultCode == Activity.RESULT_CANCELED) {

            onTwitterCancel();
        }
    }

}

      

+1


source


use below method to twitt via rest service and pass media id as null.im successfully tweets from my app



public void postToTwitter(ArrayList<String>mediaIds) {
        String message;
        if(Validator.isNotNull(preferences.getFbShareMessage())){
            message=preferences.getFbShareMessage()+" "+com.aimdek.healthwel.network.Request.HOST_URL + "/user-history/" + userHistory.getUserId() + "/" + userHistory.getId();
        }
        else {
            message = getString(R.string.google_status, HWUtil.getFullName(preferences.getUserInfo().getFirstName(), preferences.getUserInfo().getLastName()), userHistory.getSportName(), HWUtil.secondToTime(userHistory.getDuration()))+" "+com.aimdek.healthwel.network.Request.HOST_URL + "/user-history/" + userHistory.getUserId() + "/" + userHistory.getId();
        }
        String mediaId;
        if (Validator.isNotNull(mediaIds) && mediaIds.size() > 0) {
            mediaId="";
            for (int i = 0; i < mediaIds.size(); i++) {
                if (i == 0) {
                    mediaId = mediaIds.get(i);
                } else {
                    mediaId += "," + mediaIds.get(i);
                }
            }
        }
        else {
            mediaId=null;
        }
        StatusesService statusesService = twitterApiClient.getStatusesService();
        statusesService.update(message, null, null, null, null, null, null, null, mediaId, new Callback<Tweet>() {
            @Override
            public void success(Result<Tweet> result) {
                dismissProgressDialog();
                if(Validator.isNotNull(preferences.getImagePath()) && !preferences.getImagePath().isEmpty()) {
                    preferences.getImagePath().clear();
                }
                com.aimdek.healthwel.network.Request.getRequest().sendRequest(com.aimdek.healthwel.network.Request.SHARE_USER_HISTORY, TwitterIntegration.this, TwitterIntegration.this, RequestParameterBuilder.buildMapForShareUserHistory(userHistory.getId(), TwitterIntegration.this));
            }

            @Override
            public void failure(TwitterException exception) {
                if(Validator.isNotNull(preferences.getImagePath()) && !preferences.getImagePath().isEmpty()) {
                    preferences.getImagePath().clear();
                }
                dismissProgressDialog();
                finish();
                HWUtil.showToast(TwitterIntegration.this,exception.getMessage());
            }
        });
    }

      

0


source







All Articles