How to implement a ContentProvider for providing image to Gmail, Facebook, Evernote, etc

前端 未结 3 1212
南方客
南方客 2021-01-05 11:00

My previous question (Is it possible to share an image on Android via a data URL?) is related to this question. I have figured out how to share an image from my application

3条回答
  •  悲哀的现实
    2021-01-05 11:50

    Had the same problem and after lots of research and debuging here is my 5 cents: (on my android 2.3.3 and 4.2 devices)

    1. Facebook app will not use openFile(Uri uri, String mode) so we have to give it real URI (in projection[i] == MediaStore.MediaColumns.DATA) with read rights.
    2. You have to give Facebook every projection it asks you, otherwise FB-app will just repeate query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

    It is probably a hack, and wouldn't work on some sensitive data, but you can make file.setReadable(true, false); on internal file somewhere in your code and facebook will be able to see and send the img. No need for android external storage permissions. Probably there is no need for content provider if img will be readable. Can just send link in Intent. But i had strange google+ preview bechavior without provider so decided to keep it. Don't have lots of devices to test and use only Twitter, FB , Google+ ,Skype, Gmail. Works fine for now

    Here is GitHub Demo:

提交回复
热议问题