Cómo compartir la imagen de imageview?
Tengo ImageView y quiero compartir su imagen.
A continuación se muestra mi código,
- Cómo dibujar línea en imageview junto con dedo en android
- Cuando haga clic en un botón, gire la imagen en sentido horario en android
- Cargar imágenes en ImageView en Android
- Problema de carga de la vista de lista de Android
- Imagen de estiramiento en la imagen para ajustar la pantalla en xml
btshare.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View content = findViewById(R.id.full_image_view); content.setDrawingCacheEnabled(true); Bitmap bitmap = content.getDrawingCache(); File root = Environment.getExternalStorageDirectory(); File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg"); try { root.createNewFile(); FileOutputStream ostream = new FileOutputStream(root); bitmap.compress(CompressFormat.JPEG, 100, ostream); ostream.close(); } catch (Exception e) { e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); Uri phototUri = Uri.parse("/DCIM/Camera/image.jpg"); shareIntent.setData(phototUri); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri); startActivity(Intent.createChooser(shareIntent, "Share Via")); } });
cuando presiono el botón i obtener estos errores?
01-13 06:00:19.282: W/System.err(6199): java.io.FileNotFoundException: /storage/emulated/0: open failed: EISDIR (Is a directory) 01-13 06:00:19.286: W/System.err(6199): at libcore.io.IoBridge.open(IoBridge.java:409) 01-13 06:00:19.286: W/System.err(6199): at java.io.FileOutputStream.<init>(FileOutputStream.java:88) 01-13 06:00:19.294: W/System.err(6199): at java.io.FileOutputStream.<init>(FileOutputStream.java:73) 01-13 06:00:19.294: W/System.err(6199): at com.safshari.mandegar.FullImageActivity$3.onClick(FullImageActivity.java:116) 01-13 06:00:19.294: W/System.err(6199): at android.view.View.performClick(View.java:4240) 01-13 06:00:19.294: W/System.err(6199): at android.view.View$PerformClick.run(View.java:17721) 01-13 06:00:19.298: W/System.err(6199): at android.os.Handler.handleCallback(Handler.java:730) 01-13 06:00:19.298: W/System.err(6199): at android.os.Handler.dispatchMessage(Handler.java:92) 01-13 06:00:19.298: W/System.err(6199): at android.os.Looper.loop(Looper.java:137) 01-13 06:00:19.302: W/System.err(6199): at android.app.ActivityThread.main(ActivityThread.java:5103) 01-13 06:00:19.302: W/System.err(6199): at java.lang.reflect.Method.invokeNative(Native Method) 01-13 06:00:19.302: W/System.err(6199): at java.lang.reflect.Method.invoke(Method.java:525) 01-13 06:00:19.302: W/System.err(6199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 01-13 06:00:19.306: W/System.err(6199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 01-13 06:00:19.306: W/System.err(6199): at dalvik.system.NativeStart.main(Native Method) 01-13 06:00:19.310: W/System.err(6199): Caused by: libcore.io.ErrnoException: open failed: EISDIR (Is a directory) 01-13 06:00:19.310: W/System.err(6199): at libcore.io.Posix.open(Native Method) 01-13 06:00:19.310: W/System.err(6199): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 01-13 06:00:19.310: W/System.err(6199): at libcore.io.IoBridge.open(IoBridge.java:393) 01-13 06:00:19.314: W/System.err(6199): ... 14 more 01-13 06:00:19.618: E/Genymotion(489): Could not open '/sys/class/power_supply/genymotion_fake_path/present'
¿qué debo hacer y qué permisos necesita mi programa? Ya he declarado los siguientes permisos,
<uses-permission android:name="android.permission.SET_WALLPAPER"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- Android - Vista de imagen en el centro en toda la resolución de la pantalla
- PDFRenderer zoom y voltea
- Cambiar el tamaño de ImageView en tiempo de ejecución mediante un botón - Android
- ¿Cómo puedo especificar una imagen de marcador de posición?
- Animación para Android
- Android: actualiza el mapa de bits del hilo del temporizador
- ListView haga clic para mostrar la imagen en ImageView
- Android Volley - ¿Cómo animar la carga de imágenes?
Intente abajo el código para compartir su imagen:
Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg")); startActivity(Intent.createChooser(share,"Share via"));
Añade estos permisos a AndroidMenifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Código Final para que cualquiera pueda usar para guardar y compartir imágenes de imageview:
View content = findViewById(R.id.full_image_view); content.setDrawingCacheEnabled(true); Bitmap bitmap = content.getDrawingCache(); File root = Environment.getExternalStorageDirectory(); File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg"); try { cachePath.createNewFile(); FileOutputStream ostream = new FileOutputStream(cachePath); bitmap.compress(CompressFormat.JPEG, 100, ostream); ostream.close(); } catch (Exception e) { e.printStackTrace(); } Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath)); startActivity(Intent.createChooser(share,"Share via")); }
Feliz codificación
Debe agregar este permiso
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
intente crear la memoria caché para almacenar esta imagen primero y luego compartirla porque sólo puede compartir imágenes que sean públicas para otras aplicaciones también. No puede compartir el contenido que sea privado para su aplicación.
use Context.getExternalCacheDir () para crear caché y luego compartir el contenido de esta caché
- Android: ¿Cómo puedo añadir un pie de página a una vista de pantalla completa?
- ¿Existe una biblioteca de compatibilidad para / way para usar NotificationBuilder en Gingerbread y abajo?