2011-11-28 10 views
22

Quiero dar al usuario la posibilidad de compartir una imagen y un texto con Twitter y Facebook.Problemas para compartir texto e imagen combinados con SHARE INTENT en Twitter

En realidad, mi código puede iniciar la intención de compartir de Android y si el usuario selecciona Facebook, todo funciona bien, la imagen se adjunta y el texto se muestra en el cuerpo del nuevo estado.

Pero algo está mal con Twitter, si solo pongo una Imagen todo funciona bien, la imagen es detectada por Twitter y automáticamente cargada en twipic, luego Twitter publica el enlace de la imagen en el tweet. Pero si pongo una imagen y un texto, entonces, Twitter no detecta la imagen y solo pone el texto en el tweet, la imagen es ignorada. ¿Qué está mal?

este es mi código:

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
Uri screenshotUri = Uri.parse("file:///sdcard/image.jpg"); 
sharingIntent.setType("image/*"); 
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status"); 
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); 
startActivity(Intent.createChooser(sharingIntent, "Share image using")); 
+0

Tener un vistazo a este post: http://stackoverflow.com/questions/2077008/android-intent-for-twitter-application/9151983#9151983 – Derzu

Respuesta

14

especifique el tipo MIME también para el texto. "text/plain" es el tipo de datos de texto MIME. Intente usar "*/*" como MIME, para que pueda enviar cualquier tipo de datos genérico.

También intente cambiar ACTION_SEND a ACTION_SEND_MULTIPLE que se especializó en la entrega de datos múltiples.

Más información acerca ACTION_SEND_MULTPLE y de MIME tipos:

http://developer.android.com/reference/android/content/Intent.html

+0

Probé con */* y no funcionó. No puedo usar ACTION_SEND_MULTIPLE porque no existe, al menos en Android 1.5. – NullPointerException

+1

Ahora probé con ACTION_SEND_MULTIPLE y Android api 4, y no funciona. – NullPointerException

+0

¿Has probado '" */* "'? –

22

todavía puede tratar con ACTION_SEND, sin utilizar el ACTION_SEND_MULTIPLE.

ACTION_SEND_MULTIPLE dio lugar a una fuerza de cierre, cuando traté de crear nuevos intentos por compartir con Gmail, G +, etc.

Esto funcionó perfecto para mí:

Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    Uri uri = Uri.parse("file:///sdcard/image.jpg"); 
    shareIntent.setType("*/*"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status"); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
    return shareIntent; 
+0

¿cómo se construye el uri? – Radu

+0

ver respuesta editada – Paschalis

+1

@ Paschalis: pruebo tu bacalao, pero cuando estoy con Facebook me doy una tostada como ** "adjunta solo fotos o videos" ** alguna idea de cómo puedo solucionarlo? –

Cuestiones relacionadas