Added instagram story
This commit is contained in:
parent
8e387264d5
commit
ddc1edfc82
5 changed files with 150 additions and 82 deletions
|
@ -19,7 +19,6 @@ import android.content.Intent
|
|||
import android.net.Uri
|
||||
import androidx.core.app.ActivityCompat
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
|
||||
/**
|
||||
* Created by hemanths on 2020-02-02.
|
||||
|
@ -28,22 +27,24 @@ import code.name.monkey.retromusic.model.Song
|
|||
object Share {
|
||||
|
||||
private const val INSTAGRAM_PACKAGE_NAME = "com.instagram.android"
|
||||
private const val MEDIA_TYPE_JPEG = "jpg"
|
||||
|
||||
fun shareFileToInstagram(context: Context, song: Song, uri: Uri) {
|
||||
fun shareFileToInstagram(context: Context, uri: Uri) {
|
||||
val feedIntent = Intent(Intent.ACTION_SEND)
|
||||
feedIntent.type = "image/*"
|
||||
feedIntent.putExtra(Intent.EXTRA_TITLE, song.title)
|
||||
feedIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
|
||||
feedIntent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
feedIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
|
||||
feedIntent.putExtra("top_background_color", "#33FF33")
|
||||
feedIntent.putExtra("bottom_background_color", "#FF00FF")
|
||||
|
||||
val storiesIntent = Intent("com.instagram.share.ADD_TO_STORY")
|
||||
storiesIntent.setDataAndType(uri, "jpg")
|
||||
//storiesIntent.setDataAndType(uri, MEDIA_TYPE_JPEG)
|
||||
storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
storiesIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
|
||||
storiesIntent.putExtra(Intent.EXTRA_TITLE, song.title)
|
||||
storiesIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
|
||||
context.grantUriPermission("com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
storiesIntent.type = MEDIA_TYPE_JPEG
|
||||
storiesIntent.putExtra("top_background_color", "#33FF33")
|
||||
storiesIntent.putExtra("bottom_background_color", "#0000FF")
|
||||
storiesIntent.putExtra("content_url", "https://www.google.com")
|
||||
val chooserIntent = Intent.createChooser(feedIntent, context.getString(R.string.social_instagram))
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(storiesIntent))
|
||||
ActivityCompat.startActivity(context, chooserIntent, null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue