diff --git a/app/src/main/kotlin/jackall/moncalc/utils/ShareUtil.kt b/app/src/main/kotlin/jackall/moncalc/utils/ShareUtil.kt new file mode 100644 index 0000000..eeb5fd4 --- /dev/null +++ b/app/src/main/kotlin/jackall/moncalc/utils/ShareUtil.kt @@ -0,0 +1,41 @@ +package jackall.moncalc.utils + +import android.app.Activity +import android.graphics.Bitmap +import android.net.Uri +import android.support.v4.app.ShareCompat +import java.io.File +import java.io.FileOutputStream +import java.io.IOException + + +/** + * Created by matsumoto_k on 2017/11/07. + */ +class ShareUtil { + companion object { + fun shareImageAndText(activity: Activity, bitmap: Bitmap, title: String, subject: String, text: String) { + val builder = ShareCompat.IntentBuilder.from(activity) + builder.setChooserTitle(title) + builder.setSubject(subject) + builder.setText(text) + + val cache = activity.externalCacheDir + val sharefile = File(cache, "toshare.png") + try { + val out = FileOutputStream(sharefile) + bitmap.compress(Bitmap.CompressFormat.PNG, 100, out) + out.flush() + out.close() + } catch (e: IOException) { + + } + + val image = Uri.parse("file://" + sharefile) + + builder.setStream(image) + builder.setType("image/jpeg") + builder.startChooser() + } + } +} \ No newline at end of file