Skip to content

Instantly share code, notes, and snippets.

@illuzor illuzor/WallpaperFragment.kt Secret
Created Sep 28, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.