Created
July 8, 2019 16:10
-
-
Save techiesatish/8ae5cc1da06f580917c0d7ec58911868 to your computer and use it in GitHub Desktop.
Share Image via whatsapp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Bitmap takeScreenshot() { | |
View rootView = findViewById(android.R.id.content).getRootView(); | |
rootView.setDrawingCacheEnabled(true); | |
return rootView.getDrawingCache(); | |
} | |
private String saveImage(Bitmap finalBitmap) { | |
File myDir = new File(Environment.getExternalStorageDirectory().toString() + "/GoodOffers"); | |
myDir.mkdirs(); | |
String fname = "GoodOffers_"+ mData.mOffers +".jpeg"; | |
File file = new File(myDir, fname); | |
if (file.exists()) file.delete (); | |
try { | |
FileOutputStream out = new FileOutputStream(file); | |
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); | |
out.flush(); | |
out.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return file.getAbsolutePath(); | |
} | |
private void shareImage(String uri) { | |
Intent intent = new Intent(); | |
intent.setAction(Intent.ACTION_SEND); | |
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |
intent.setType("image/jpeg"); | |
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "GoodOffers"); | |
intent.putExtra(android.content.Intent.EXTRA_TEXT, R.string.share_offer+R.string.playstore_url+ getApplicationContext().getPackageName()); | |
intent.setPackage("com.whatsapp"); | |
File mFile = new File(uri); | |
Uri uris = FileProvider.getUriForFile(View_Offer.this, BuildConfig.APPLICATION_ID + ".provider",mFile); | |
intent.putExtra(Intent.EXTRA_STREAM, uris); | |
try { | |
startActivity(Intent.createChooser(intent, "Share Screenshot")); | |
} catch (ActivityNotFoundException e) { | |
Toast.makeText(this, "No App Available", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
//Provider xml | |
<?xml version="1.0" encoding="utf-8"?> | |
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | |
<root-path name="external_files" path="/" /> | |
</paths> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment