twitter-kit-android icon indicating copy to clipboard operation
twitter-kit-android copied to clipboard

IllegalArgumentException: column '_data' does not exist

Open koral-- opened this issue 8 years ago • 14 comments

  • Steps to reproduce the problem: Use AppCardBuilder#imageUri() with content Uri serviced by provider which does not expose _data column eg. FileProvider
java.lang.IllegalArgumentException: column '_data' does not exist
    at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
    at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:78)
    at com.twitter.sdk.android.tweetcomposer.FileUtils.resolveFilePath(FileUtils.java:87)
    at com.twitter.sdk.android.tweetcomposer.TweetUploadService.com.twitter.sdk.android.tweetcomposer.FileUtils.getPath(TweetUploadService.java:2062)
                                                             uploadAppCardTweet
                                                             onHandleIntent
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.os.HandlerThread.run(HandlerThread.java:61)
  • Expected behavior: Mentioned Uris should work. As you see, _data column may not exist, image may even not be served from file. You should use appropriate ContentResolver methods to retrieve image content.
  • Android API Version: doesn't matter
  • Android Device: doesn't matter
  • Artifact Versions (run ./gradlew :app:dependencies):
+--- com.twitter.sdk.android:twitter:1.13.1
|    +--- com.digits.sdk.android:digits:1.10.3
|    |    +--- io.fabric.sdk.android:fabric:1.3.10
|    |    \--- com.twitter.sdk.android:twitter-core:1.6.6
|    |         +--- com.squareup.retrofit:retrofit:1.8.0
|    |         |    \--- com.google.code.gson:gson:2.3
|    |         +--- io.fabric.sdk.android:fabric:1.3.10
|    |         \--- com.google.code.gson:gson:2.2.4 -> 2.3
|    +--- io.fabric.sdk.android:fabric:1.3.10
|    +--- com.twitter.sdk.android:tweet-composer:1.0.3
|    |    +--- io.fabric.sdk.android:fabric:1.3.10
|    |    +--- com.twitter:twitter-text:1.13.0
|    |    \--- com.squareup.picasso:picasso:2.5.2
|    +--- com.twitter.sdk.android:tweet-ui:1.10.1
|    |    +--- io.fabric.sdk.android:fabric:1.3.10
|    |    +--- com.android.support:support-v4:22.2.0 -> 23.3.0 (*)
|    |    +--- com.twitter.sdk.android:twitter-core:1.6.6 (*)
|    |    \--- com.squareup.picasso:picasso:2.5.2
|    \--- com.twitter.sdk.android:twitter-core:1.6.6 (*)

koral-- avatar May 06 '16 16:05 koral--

This is critical. PLease fix ASAP.

KishoreBabuIN avatar May 31 '17 12:05 KishoreBabuIN

We'll have to consider whether to resolve this in an older version of Twitter Kit. The latest (version 3) no longer supports programmatic creation of App Cards and the associated methods have been removed.

andypiper avatar May 31 '17 13:05 andypiper

I've reported this issue more than a year ago and I don't use that method now, but just curious. There is a replacement API method: [Added] The ComposerActivity.Builder#image method was added for attaching an image to the Tweet. Does it support content:// URIs?

koral-- avatar May 31 '17 14:05 koral--

I'm using the following method:

ComposerActivity.Builder(this)
                .session(session)
                .image(uri)
                .text(mentions)
                .hashtags(hashtags)
                .createIntent()

and i'm using version 3.0 of Twitter Kit. If i pass the Uri in the content:// scheme from my File Provider.. this same error is thrown.

KishoreBabuIN avatar May 31 '17 14:05 KishoreBabuIN

We still only support local files for the embedded composer but this is something we are looking to improve in the next release.

efrohnhoefer avatar May 31 '17 20:05 efrohnhoefer

I need to attach remote image to a Tweet and Twitter Kit does not support attaching remote images to a Tweet. To workaround this, I'm passing the Uri of the cache file from Glide to the Composer Activity. The image is shown in the ComposerActivity but crashes when I tap the Tweet button with the same exception as mentioned above. I'm using Twitter Kit v3.0. @efrohnhoefer Wouldn't cache files count as local files?

Found this comment on a Glide issue. Maybe it can help to resolve the issue.

harryio avatar Jun 01 '17 08:06 harryio

Same problem here. Is there any workaround to tweet images?

Firsto avatar Sep 27 '17 08:09 Firsto

@Firsto There is but without using TweetComposerView. Workaround involves calling the REST api calls present in the SDK. You need to first upload the image at upload media endpoint, which will return the id of the uploaded image. You then need to send the uploaded image id to this endpoint in media_ids along with your text. This will create a tweet with your passed image. This is the only workaround I know as of now. In Twitter iOS SDK you even have the option to attach video and gif to the Tweet out of the box and the Android SDK is struggling to even attach an image.

harryio avatar Sep 27 '17 13:09 harryio

@harryio oh, it looks so bad :(

Anyway, TweetComposerView works properly when using image file from external storage. But I want use internal cache dir without ask permissions :-\

Firsto avatar Sep 27 '17 16:09 Firsto

I have the same problem. Please fix it,please!!!

xiaoyunfei avatar Jan 05 '18 07:01 xiaoyunfei

I have the same problem. And I solved it. It worked.

    public static Uri saveBitmapToInternalCache(Context context, Bitmap bitmap) {
    Uri targetUri = null;
    FileOutputStream fos = null;
    try {
        File imgFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), ".png", context.getCacheDir());
        //imgFile.createNewFile();
        fos = new FileOutputStream(imgFile);
        boolean compressed = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.flush();
        if (compressed) targetUri = Uri.fromFile(imgFile);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fos != null) fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return targetUri;
   }

jackyhieu1211 avatar Jan 31 '18 09:01 jackyhieu1211

This is still happening on September 2018 using 'com.twitter.sdk.android:twitter:3.1.1'

CristianCardosoA avatar Sep 06 '18 15:09 CristianCardosoA

After review FileUtils class, the best approach to share an image to Twitter is using:

MediaStore.Images.Media.insertImage(cr, bitmap, title, title)

private fun generateTwitterIntent(session : TwitterSession) : Intent {

    val bitmap = generateBitmapToShare(viewToShare)

    val cr = activity.contentResolver
    val title = getApplicationContext().packageName
    val savedURL = MediaStore.Images.Media.insertImage(cr, bitmap, title, title)

    return ComposerActivity.Builder(activity)
            .session(session)
            .image(Uri.parse(savedURL))
            .hashtags(context.getString(R.string.share_hashtag))
            .createIntent()
}

CristianCardosoA avatar Sep 08 '18 17:09 CristianCardosoA

Note: Twitter kit is no longer being actively maintained. But if you submit a PR I can still review and merge.

efrohnhoefer avatar Sep 10 '18 16:09 efrohnhoefer