How To Share Image Of Imageview?
I have ImageView and I want to share its image. Following is my code, btshare.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
Solution 1:
Final Code so anyone can use to save and share image from imageview :
Viewcontent= findViewById(R.id.full_image_view);
content.setDrawingCacheEnabled(true);
Bitmapbitmap= content.getDrawingCache();
Fileroot= Environment.getExternalStorageDirectory();
FilecachePath=newFile(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
try {
cachePath.createNewFile();
FileOutputStreamostream=newFileOutputStream(cachePath);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
Intentshare=newIntent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath));
startActivity(Intent.createChooser(share,"Share via"));
}
happy coding
Solution 2:
Try below code to share your image:
Intentshare=newIntent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(newFile(root.getAbsolutePath() + "/DCIM/Camera/image.jpg"));
startActivity(Intent.createChooser(share,"Share via"));
Add these permissions to AndroidMenifest.xml
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.INTERNET" /><uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" />
Solution 3:
You need to add this permission
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" />
Solution 4:
Bundleintent= getIntent().getExtras();
cardView = (CardView) findViewById(R.id.card);
finalStringquery= intent.getString("Query1");
db = newDataBaseHelper(Image.this);
Cursorc= db.getData(query);
if (c.getCount() != 0) {
c.moveToFirst();
do {
image = c.getString(5);
title=c.getString(3);
} while (c.moveToNext());
}
txt.setText(title);
img.setImageDrawable(getResources()
.getDrawable(getResources().getIdentifier(image, "drawable", getPackageName())));
Solution 5:
- get bitmap from imageview
imageview.buildDrawingCache();
Bitmapimage= mainimg.getDrawingCache();
- convert url
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStreambytes=newByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
Stringpath= Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
- then share button
Intentshare=newIntent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, getImageUri(this,getImageUri));
startActivity(Intent.createChooser(share,"Share via"));
Post a Comment for "How To Share Image Of Imageview?"