Dont make this as duplicate..i have tried every link and i will show following what i have tried till now
i will briefly explain my code-->
fetching image from adapter to activity-->
val bundle: Bundle = getIntent().getExtras()!!
val imgUrl: String = bundle.getString("image")!!
val imageUri = Uri.parse(imgUrl)
1-->>>
full code:--> referred from -->https://stackoverflow.com/questions/49011212/sharing-image-using-intent-on-whats-app-getting-error-sharing-failed
val bundle: Bundle = getIntent().getExtras()!!
val imgUrl: String = bundle.getString("image")!!
val imageUri = Uri.parse(imgUrl)
shareiamge.setOnClickListener {
shareImage(imageUri)
}
private fun shareImage(imagePath: Uri) {
val sharingIntent = Intent(Intent.ACTION_SEND)
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
sharingIntent.type = "image/*"
sharingIntent.putExtra(Intent.EXTRA_STREAM, imagePath)
//sharingIntent.setPackage("com.whatsapp"); for whatsapp only
startActivity(
Intent.createChooser(
sharingIntent,
"Share Image Using"
)
) // for all generic options
}
Manifest-->
<activity
android:name=".ProductDetails.Product_details"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.SEND" /> <!-- Send
action required to display activity in share list -->
<category android:name="android.intent.category.DEFAULT" /> <!--
Make activity default to launch -->
<!-- Mime type i.e. what can be shared with this activity only image and text -->
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
above code output:-->
when sharing to whatsapp or any app the file format is not supported
2--->>>refered from this-->>> Share text OR Image On Whatsapp in Android
shareiamge.setOnClickListener {
val whatsappIntent = Intent(Intent.ACTION_SEND)
whatsappIntent.type = "image/*"
whatsappIntent.putExtra(
Intent.EXTRA_STREAM,
imageUri
) //add image path
startActivity(Intent.createChooser(whatsappIntent, "Share image using"))
}
above code output:-->
when sharing to whatsapp or any app the file format is not supported
3-->>>
val bundle: Bundle = getIntent().getExtras()!!
val imgUrl: String = bundle.getString("image")!!
val imageUri = Uri.parse(imgUrl)
shareiamge.setOnClickListener {
val whatsappIntent = Intent(Intent.ACTION_SEND)
whatsappIntent.type = "image/*"
whatsappIntent.putExtra(
Intent.EXTRA_STREAM,
Uri.parse(res?.body()!!.data.product_images.get(0).image)
) //direct image from retrofit response
startActivity(Intent.createChooser(whatsappIntent, "Share image using"))
above code output:-->
when sharing to whatsapp or any app the file format is not supported
4-->>refered from this--> https://stackoverflow.com/a/25136183/12553303
val bundle: Bundle = getIntent().getExtras()!!
val imgUrl: String = bundle.getString("image")!!
val imageUri = Uri.parse(imgUrl)
shareiamge.setOnClickListener {
val intent = Intent(Intent.ACTION_SEND)
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image")
val path: String =
MediaStore.Images.Media.getContentUri(imgUrl).toString()
val screenshotUri = Uri.parse(path)
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri)
intent.type = "image/*"
startActivity(Intent.createChooser(intent, "Share image via..."))
above code output:-->
when sharing to whatsapp or any app --> sharing failed,please try again later
5--> but it is only sharing text not image
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(Intent.EXTRA_TEXT, imgUrl)
sendIntent.type = "text/plain"
startActivity(sendIntent)
values in log:-
Log.e("imgUrl",imgUrl)
Log.e("imageUri", imageUri.toString())
E/imgUrl: http://....../uploads/prod_img/thumb/medium/9dc6234da018916e545011fa1.jpeg
E/imageUri: http://..../uploads/prod_img/thumb/medium/9dc6234da018916e545011fa1.jpeg
i want to share an image need help thanks in advance