Skip to content

Add Snippets for notifications and picture-in-picture#905

Open
alabiaga wants to merge 8 commits intoandroid:mainfrom
alabiaga:main
Open

Add Snippets for notifications and picture-in-picture#905
alabiaga wants to merge 8 commits intoandroid:mainfrom
alabiaga:main

Conversation

@alabiaga
Copy link
Copy Markdown
Member

@alabiaga alabiaga commented May 6, 2026

Migrate hardcoded embedded code snippets to github snippets for notifications and Picture-in-Picture

@alabiaga alabiaga requested review from a team, kkuan2011 and yrezgui as code owners May 6, 2026 23:38
@alabiaga alabiaga requested a review from srikrishnasakunia May 6, 2026 23:38
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented May 6, 2026

Here is the summary of changes.

You are about to add 11 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive notification snippets, including permission handling, channel management, and various styles such as BigPicture, Messaging, and Media using Media3. It also includes manifest configurations for notifications and Picture-in-Picture. Feedback highlights the need for proper Compose side-effect management to prevent resource leaks with ExoPlayer and MediaSession, the use of idiomatic Kotlin properties, and the correction of invalid XML comment syntax.

Comment on lines +89 to +94
@Composable
fun deleteNotificationId(channelId: String) {
val notificationManager =
LocalContext.current.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.deleteNotificationChannel(channelId)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The function deleteNotificationId performs a side effect (deleting a notification channel) directly in the composition body. In Compose, side effects should be triggered by events or wrapped in a LaunchedEffect to avoid executing them on every recomposition. Additionally, the function name is misleading as it deletes a channel, not an ID.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment and modified method name

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the @composable annotation then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified it so that i can remove Composable

val context = LocalContext.current
val bitmapImage = BitmapFactory.decodeResource(
context.resources,
com.example.compose.snippets.R.drawable.dog
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since com.example.compose.snippets.R is already imported, you can use the simple name R.drawable.dog for better readability.

Suggested change
com.example.compose.snippets.R.drawable.dog
R.drawable.dog

}

// [START android_notification_create_group_channel]
@Composable
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, doesn't seem like a compostable, if it is, include the LaunchedEffect

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed Composable


@OptIn(UnstableApi::class)
@Composable
fun notificationStyles() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should any of these be composables? I think you only need context right, so perhaps these should be viewmodel background thread kicked off using AndroidViewModel to get access to context?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just used contextcompat and just passing in context. I am taking the examples from DAC so i want to make it as simple as possible.

<application>
<!-- [START android_jpip_manifest_config] -->
<activity
android:name="com.example.compose.snippets.pictureinpicture.NavOrVideoCallJpipActivity"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Jpip crucial for meaning here? Accidental name?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not. removed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to remove Jpip from NavOrVideoCallJpipActivity?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these rather be vectors?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, i can convert.

Copy link
Copy Markdown
Contributor

@kkuan2011 kkuan2011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good from a snippets repo perspective

limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- [START android_manifest_config] -->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: it's actually not required to put mainfest snippets in the repo, but up to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants