Tweet using TweetComposer in Android

510 views Asked by At

I am using TweetComposer for posting a tweet from my Android app. Code Snippet:

Uri uri= Uri.parse(path);

TweetComposer.Builder builder = new TweetComposer.Builder(this)
.text("My First Post")
.image(uri);
builder.show();

Here path is local path to the image stored in device's SDcard. I am sure m pretty much doing it right but still this is not posting the image . Can someone help in figuring out what Am I doing wrong?

I get a message "Unable to load image" when test it on my device having native twitter app.

1

There are 1 answers

0
Aniruddha K.M On

i was also struck in the same issue assuming you are using twitter4j, try this method

public static String getRealPathFromURI(Context context, Uri contentUri) {
        Cursor cursor = null;
        try {
            String[] proj = { MediaStore.Images.Media.DATA };
            cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }