Cómo compartir imagen + texto juntos usando ACTION_SEND en android?
Quiero compartir texto + imagen juntos usando ACTION_SEND en android, estoy usando código debajo, puedo compartir solamente la imagen pero no puedo compartir el texto con él,
private Uri imageUri; private Intent intent; imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher"); intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Hello"); intent.putExtra(Intent.EXTRA_STREAM, imageUri); intent.setType("image/*"); startActivity(intent);
¿Alguna ayuda en esto?
- Cómo filtrar correctamente Paquete reemplazado broadcast
- ¿Cuáles son los usos de main, default y launcher en el archivo de manifiesto en android
- IntentFilter en NFC - Xamarin - C #
- Manejo de URL específicas con filtros de intenciones en Xamarin Mono para Android
- ¿Cómo puedo iniciar la actividad PRINCIPAL con la ayuda de <intento-filtro>?
- ¿Cuál es el propósito de "android.intent.category.DEFAULT"?
- Cómo filtrar sólo una URL específica con filtro de intenciones
- Spotify intención en android?
- Android PhoneGap intento de filtro, el navegador de volver a ejecutar la aplicación?
- Pestañas personalizadas de Chrome y filtro de intenciones
- ¿Qué son exactamente los filtros de intención?
- BroadcastReceiver - onReceive Not Being Called
- Abrir mi aplicación para un determinado archivo y extensión de URL - intento-filtro no funciona como se pretende
Puede compartir texto sin formato mediante estos códigos
String shareBody = "Here is the share content body"; Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));
Por lo que su código completo (su imagen + texto) se convierte en
private Uri imageUri; private Intent intent; imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher"); intent = new Intent(Intent.ACTION_SEND); //text intent.putExtra(Intent.EXTRA_TEXT, "Hello"); //image intent.putExtra(Intent.EXTRA_STREAM, imageUri); //type of things intent.setType("*/*"); //sending startActivity(intent);
Acabo de reemplazar image/*
con */*
Actualización :
Uri imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher"); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello"); shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); shareIntent.setType("image/jpeg"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, "send"));
Es posible que la aplicación de uso compartido (FB, twitter, etc) no tenga permisos para leer la imagen.
El documento de Google dice:
La aplicación receptora necesita permiso para acceder a los datos a los que Uri señala. Las maneras recomendadas de hacer esto son:
http://developer.android.com/training/sharing/send.html
No estoy seguro de que las aplicaciones de uso compartido tengan permisos para leer una imagen en el paquete de nuestras aplicaciones. Pero mis archivos guardados en
Activity.getFilesDir()
No se puede leer. Como se sugiere en el enlace anterior, podemos considerar almacenar imágenes en el MediaStore, donde las aplicaciones de uso compartido tienen permisos de lectura.
Update1: Lo siguiente es código de trabajo para compartir la imagen con texto en Android 4.4.
Bitmap bm = BitmapFactory.decodeFile(file.getPath()); intent.putExtra(Intent.EXTRA_TEXT, Constant.SHARE_MESSAGE + Constant.SHARE_URL); String url= MediaStore.Images.Media.insertImage(this.getContentResolver(), bm, "title", "description"); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url)); intent.setType("image/*"); startActivity(Intent.createChooser(intent, "Share Image"));
El efecto secundario es que agregamos una imagen en el MediaStore.
Intente usar este código. Estoy cargando ic_launcher de drawable.you puede cambiar esto con su archivo de gallary o bitmap.
void share() { Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpeg"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes); File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"); try { f.createNewFile(); FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray()); } catch (IOException e) { e.printStackTrace(); } share.putExtra(Intent.EXTRA_TEXT, "hello #test"); share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg")); startActivity(Intent.createChooser(share, "Share Image")); }
Por favor, eche un vistazo a este código trabajado para mí para compartir un texto y una imagen juntos
Intent shareIntent; Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher); String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/Share.png"; OutputStream out = null; File file=new File(path); try { out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } path=file.getPath(); Uri bmpUri = Uri.parse("file://"+path); shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.putExtra(Intent.EXTRA_TEXT,"Hey please check this application " + "https://play.google.com/store/apps/details?id=" +getPackageName()); shareIntent.setType("image/png"); startActivity(Intent.createChooser(shareIntent,"Share with"));
No olvide dar permiso WRITE_EXTERNAL_STORAGE
También en facebook sólo puede compartir la imagen porque facebook no está permitiendo compartir el texto a través de la intención
Por accidente (la parte del mensaje de texto, había renunciado a eso), me di cuenta de que cuando elegí la aplicación de mensajes para manejar la solicitud, la aplicación de mensajes se abriría con el texto de Intent.EXTRA_SUBJECT más la imagen lista para enviar, espero ayuda.
String[] recipient = {"your_email_here"}; Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, recipient); intent.putExtra(Intent.EXTRA_SUBJECT, "Hello, this is the subject line"); intent.putExtra(Intent.EXTRA_TEXT, messageEditText.getText().toString()); intent.putExtra(Intent.EXTRA_STREAM, imageUri); intent.setType("image/*");
He estado buscando la solución de esta pregunta por un tiempo y encontré este uno en marcha, espero que ayude.
private BitmapDrawable bitmapDrawable; private Bitmap bitmap1; //write this code in your share button or function bitmapDrawable = (BitmapDrawable) mImageView.getDrawable();// get the from imageview or use your drawable from drawable folder bitmap1 = bitmapDrawable.getBitmap(); String imgBitmapPath= MediaStore.Images.Media.insertImage(getContentResolver(),bitmap1,"title",null); Uri imgBitmapUri=Uri.parse(imgBitmapPath); String shareText="Share image and text"; Intent shareIntent=new Intent(Intent.ACTION_SEND); shareIntent.setType("*/*"); shareIntent.putExtra(Intent.EXTRA_STREAM,imgBitmapUri); shareIntent.putExtra(Intent.EXTRA_TEXT, shareText); startActivity(Intent.createChooser(shareIntent,"Share Wallpaper using"));
- ¿Por qué el emulador de Android informa "dispositivo virtual desconocido", cuando el dispositivo está en mi directorio de usuario?
- Cómo crear varias aplicaciones de Android desde una base de código