studio intent extra_stream createchooser and action_send android android-intent intentfilter android-sharing

intent - share image android studio



¿Cómo compartir imagen+texto juntos usando ACTION_SEND en android? (7)

Quiero compartir texto + imagen usando ACTION_SEND en android, estoy usando el código a continuación, puedo compartir solo la imagen pero no puedo compartir el texto con ella,

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?


Es posible que la aplicación para compartir (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 señalados por Uri. Las formas recomendadas de hacer esto son:

http://developer.android.com/training/sharing/send.html

No estoy seguro de que las aplicaciones para compartir 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 MediaStore, donde las aplicaciones para compartir tienen permisos para leer.

Actualización 1: El siguiente código funciona para compartir imágenes 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 MediaStore.


He estado buscando una solución a esta pregunta por un tiempo y encontré esta en funcionamiento, 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 accidente (la parte del mensaje de texto, había renunciado a eso), noté que cuando elegía la aplicación Mensajes para manejar la solicitud, la aplicación de mensajes se abrí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/*");


Por favor, eche un vistazo a este código que me ayudó a 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 te olvides de dar permiso WRITE_EXTERNAL_STORAGE

también en Facebook solo puede compartir la imagen porque Facebook no permite compartir el texto a través de la intención


intente usar este código. Estoy cargando ic_launcher desde drawable. Puede cambiar esto con su archivo desde 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")); }


puedes compartir texto sin formato con 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)));

para que su código completo (su imagen + texto) se convierta

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"));


String text = "Look at my awesome picture"; Uri pictureUri = Uri.parse("file://my_picture"); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, text); shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); shareIntent.setType("image/*"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(shareIntent, "Share images..."));