Android Kaki

Build beautiful, usable products using required Components for Android.

Sharesheet-Android14 tùy Customized Actions


With the discharge of first take a look at model belong to Android14we now have a brand new characteristic referred to as CustomActions for Sharesheet.

Right here we’ll discover this new characteristic and see how we will add our personal customized actions ARRIVE Share board.

In Android we’ll see the next S customarycowl with a number of choices every time we need to share one thing.

Commonplace sharing board
  • Have act rapidly And utility That might be deal with the Content material that we wish share

Let’s add some customized actions

  • With the assistance of a brand new one Motion API ChooserWe will outline our personal SelectorAction
  • We’ll use ChooserAction.Builder ARRIVE construct SelectorAction

Carry out

Create a Selector motion

ChooserAction.Builder obtain 3 parameters – Icons, Labels, Pending

  • To create one Pending
  val pendingIntent = PendingIntent.getActivity(
context,
0,
Intent(Intent.ACTION_WEB_SEARCH).apply {
putExtra(SearchManager.QUERY, "Search on internet 🌐.")
},
PendingIntent.FLAG_IMMUTABLE
)
  • To create one the act of selecting utilizing PendingIntent that we created within the earlier step
val customAction = ChooserAction.Builder(
// Icon
Icon.createWithResource(context, R.drawable.baseline_screen_share_24),
// Label
"CustomAction-Android14",
// PendingIntent
pendingIntent
).construct()
  • Create a intention for selector
val intent = Intent(Intent.ACTION_SEND).apply {
sort = "textual content/plain"
putExtra(Intent.EXTRA_TEXT, "Pattern textual content to ship.")
}
  • Create a Selector utilizing intention
val chooserIntent = Intent.createChooser(intent, "Android-14").
  • Add customized actions based on the consumer’s intent

Add customized actions based on meant use Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS

we have to go customized actionsas an array even when we now have Distinctive customized motion.

val chooserIntent = Intent.createChooser(intent, "Android-14").apply {
// We have to go an array
putExtra(Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS, arrayOf(customAction))
}

Might be mixed with all codes


@RequiresApi(Construct.VERSION_CODES.UPSIDE_DOWN_CAKE)
class MainActivity : ComponentActivity() {

override enjoyable onCreate(savedInstanceState: Bundle?) {
tremendous.onCreate(savedInstanceState)
// 1. Create chooser actions
val chooserActions = buildCustomShareSheetActions(this)
// 2. Create chooser intent
val chooserIntent = buildChooserIntent(chooserActions)
setContent {
GrammaticalInflectionAPITheme {
Floor(modifier = Modifier, colour = MaterialTheme.colorScheme.background) {
MainComposable {
// Launch chooser intent
startActivity(chooserIntent)
}
}
}
}
}

non-public enjoyable buildCustomShareSheetActions(context: Context): Array {
val pendingIntent = PendingIntent.getActivity(
context,
0,
Intent(Intent.ACTION_WEB_SEARCH).apply {
putExtra(SearchManager.QUERY, "Search on internet 🌐")
},
PendingIntent.FLAG_IMMUTABLE
)

val customAction = ChooserAction.Builder(
Icon.createWithResource(context, R.drawable.baseline_screen_share_24),
"CustomAction-Android14",
pendingIntent
).construct()

return arrayOf(customAction)
}

non-public enjoyable buildChooserIntent(chooserActions: Array): Intent {
val intent = Intent(Intent.ACTION_SEND).apply {
sort = "textual content/plain"
putExtra(Intent.EXTRA_TEXT, "Pattern textual content to ship.")
}
val chooserIntent = Intent.createChooser(intent, "Android-14").apply {
putExtra(Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS, chooserActions)
}
return chooserIntent
}
}

Pattern code

GitHub – navczydev/Android14Samples at customized

Performances

Presenter

  • Overview of Options and API | Android developer
  • SelectorAction | Android developer
  • intention | Android developer

Preserve contact

  • Nav Singh (@[email protected])
  • navczydev – Overview

https://www.linkedin.com/in/navczydev/

JavaScript isn’t accessible.


Sharesheet-Android14 Customized Actions have been initially printed in ProAndroidDev on Medium, the place persons are persevering with the dialog by bookmarking and replying to this story.



John Wick: Chapter 4 (FREE) FULLMOVIE The Super Mario Bros Movie avatar 2 Where To Watch Creed 3 Free At Home Knock at the Cabin (2023) FullMovie Where To Watch Ant-Man 3 and the Wasp: Quantumania Cocaine Bear 2023 (FullMovie) Scream 6 Full Movie

Updated: April 15, 2023 — 2:49 pm

Leave a Reply

Your email address will not be published. Required fields are marked *

androidkaki.com © 2023 Android kaki