Skip to content

Instantly share code, notes, and snippets.

@illuzor
Created September 28, 2018 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/7889e1f3c0c602dc8087135690a3ddc2 to your computer and use it in GitHub Desktop.
Save illuzor/7889e1f3c0c602dc8087135690a3ddc2 to your computer and use it in GitHub Desktop.
private fun shareWallpaper() {
val sharingIntent = ShareCompat.IntentBuilder
.from(activity)
.setType("image/*")
.intent
if (activity!!.packageManager.resolveActivity(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY) == null) {
toast(R.string.no_apps_for_share)
} else {
sharingIntent.putExtra(Intent.EXTRA_STREAM, imageFileUri)
val activities = activity!!.packageManager.queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY)
for (activity in activities) {
getActivity()!!.grantUriPermission(activity.activityInfo.packageName, imageFileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivityForResult(Intent.createChooser(sharingIntent, getString(R.string.share_image)), SHARING_REQUEST_CODE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment