Intención de Android Compartir mediante url de imagen externa
No podía dejar de notar que todos los ejemplos de compartir imágenes con Intent utilizan archivos almacenados localmente. Cada vez que intento utilizar una url externa, facebook, twitter, etc. me da un brindis diciendo que "uno o más elementos de medios no podrían ser agregados".
¿Debo guardar una copia de la imagen localmente? Si es así, ¿cómo hago eso?
- ¿Qué es un filtro de intenciones que solo mostraría una aplicación en el menú compartido al compartir una URL?
- Intent.ACTION_SEND WhatsApp
- Compartir archivos pdf a través de mi aplicación en android
- ¿Cómo forzar Share Intent a abrir una aplicación específica?
- Filtro de intenciones sólo para archivos
- Android: compartir de forma fiable una imagen de los activos a través de mensajería, G +, twitter, facebook?
- El diálogo compartido no funciona
- ¿Cómo compartir el texto de WhatsApp desde mi aplicación?
- ¿Cómo subir videos a youtube en android?
- Compartir Bitmap () en android para twitter, facebook, correo
4 Solutions collect form web for “Intención de Android Compartir mediante url de imagen externa”
Gracias @ user2245247 por el enlace
Contiene la respuesta correcta para compartir la imagen desde una URL remota.
Utilizar una biblioteca externa
// Get access to ImageView ImageView ivImage = (ImageView) findViewById(R.id.ivResult); // Fire async request to load image Picasso.with(context).load(imageUrl).into(ivImage);
Después de que la imagen se haya cargado correctamente en la vista de imagen, active el método para la intención de compartir.
// Can be triggered by a view event such as a button press public void onShareItem(View v) { // Get access to bitmap image from view ImageView ivImage = (ImageView) findViewById(R.id.ivResult); // Get access to the URI for the bitmap Uri bmpUri = getLocalBitmapUri(ivImage); if (bmpUri != null) { // Construct a ShareIntent with link to image Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); // Launch sharing dialog for image startActivity(Intent.createChooser(shareIntent, "Share Image")); } else { // ...sharing failed, handle error } } // Returns the URI path to the Bitmap displayed in specified ImageView public Uri getLocalBitmapUri(ImageView imageView) { // Extract Bitmap from ImageView drawable Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable){ bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png"); file.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; }
Asegúrese de tener los siguientes permisos dados.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
A continuación le mostramos cómo compartir un enlace:
Intent intent = new Intent(Intent.ACTION_SEND); Uri uri = Uri.parse("http://linkto.com/your_image.png"); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_STREAM, String.valueOf(uri)); startActivity(intent);
Hay posibles soluciones: Compartiendo contenido con intentos
Otra forma alternativa de lograr esto con el uso del método de la respuesta anterior es:
Picasso.with(this).load(imageurl).into(shareTarget); private Target shareTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { // Get access to the URI for the bitmap Uri bmpUri = getLocalBitmapUri(bitmap); if (bmpUri != null) { // Construct a ShareIntent with link to image Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text)); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/*"); // Launch sharing dialog for image startActivity(Intent.createChooser(shareIntent, "Share Image")); } else { // ...sharing failed, handle error } } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; public Uri getLocalBitmapUri(Bitmap bmp) { // Store image to default external storage directory Uri bmpUri = null; try { File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png"); file.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; }
- Android: obtener el tamaño de archivo de la imagen antes de compartirla (Intent.ACTION_SEND)
- Compartir archivo de imagen desde el directorio de caché Via Intent ~ android
- ¿Cómo puedo añadir mi aplicación de Android al diálogo compartido?
- Compartir enlace y texto con Android Facebook SDK 3.0
- ¿Cómo activar el botón "Compartir" en la aplicación Android?
- Intent.ACTION_VIEW para la imagen de Android
- Propuesta de participación de Android para facebook- compartir texto y enlace
- Android / Google Plus - No puedo compartir la imagen de mi proveedor de contenido
- Android: no obtiene el texto adecuado cuando se comparte con aplicaciones incorporadas
- Android intención action_send opción sólo una vez