简体   繁体   English

如何创建类似于Google的Play音乐应用的通知

[英]How to create a notification similar to Play Music app from Google

I'm trying to create a notification that is very similar to what the "Play Music" app from Google uses. 我正在尝试创建一个与Google使用的“Play Music”应用程序非常类似的通知。

播放音乐应用通知

Few questions that hopefully someone can answer. 很少有人希望有人可以回答这些问题。

  1. Is this notification done with custom RemoteViews? 此通知是否使用自定义RemoteViews完成?
  2. Is the X for closing the widget part of the NotificationCompat.Builder APIs? 是否用于关闭NotificationCompat.Builder API的小部件部分? or simply part of a custom RemoteView? 或者只是自定义RemoteView的一部分?
  3. If it is all custom views how can I set a custom RemoteView for minimized and maximized states? 如果是所有自定义视图,如何为最小化和最大化状态设置自定义RemoteView?

Yes, all of that is done with custom RemoteViews . 是的,所有这些都是通过自定义RemoteViews完成的。 You'll see in the docs for Notification , there's a field for bigContentView along with contentView . 您将在Notification文档中看到, bigContentViewcontentView都有一个字段。

I know I am very late to answer, but this is for new people trying out media notifications. 我知道我很晚才回答,但这是针对尝试媒体通知的新人。

  1. No need to use RemoteViews . 无需使用RemoteViews We can now simply use NotificationCompat.MediaStyle() . 我们现在可以简单地使用NotificationCompat.MediaStyle() It works perfectly as needed, and brings uniformity in the Media consumption experience. 它可以根据需要完美运行,并使Media消费体验更加统一。

  2. When using MediaStyle notifications there will be no X button for versions > Lollipop. 使用MediaStyle通知时,版本> Lollipop将没有X按钮。 Rather we make the notification dismissable when in Paused state. 相反,我们在暂停状态下使通知不可用。 In such cases the process to be followed is shown in the this link . 在这种情况下,要遵循的过程显示在此链接中

  3. The MediaStyle notification has setShowActionsInCompactView() to define which all actions to show in Compact mode. MediaStyle通知具有setShowActionsInCompactView()以定义在Compact模式下显示的所有操作。 The following is a snippet: 以下是一个片段:

      notificationBuilder.addAction(R.drawable.notification_play, "Play", createPlayIntent()); notificationBuilder.addAction(R.drawable.notification_next, "Next", createNextIntent()) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setPriority(NotificationCompat.PRIORITY_MAX) .setStyle(new NotificationCompat.MediaStyle() .setShowCancelButton(true) .setCancelButtonIntent(createPlayIntent()) .setShowActionsInCompactView(0, 1, 2); 

This should help you in setting up the whole Media notification as needed. 这可以帮助您根据需要设置整个媒体通知。 Happy coding! 快乐的编码!

  1. create statusbar_expanded.xml in res/layout-v16/ 在res / layout-v16 /中创建statusbar_expanded.xml

<ImageView
    android:id="@+id/thumbnail"
    android:layout_width="@dimen/notification_expanded_height"
    android:layout_height="@dimen/notification_expanded_height"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:src="@drawable/notification"
    android:scaleType="fitXY" />

<LinearLayout
    android:id="@+id/buttons"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/thumbnail"
    android:divider="?android:listDivider"
    android:dividerPadding="12.0dip"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:showDividers="middle" >

    <ImageButton
        android:id="@+id/prev"
        android:layout_width="0.0dip"
        android:layout_height="@dimen/play_controls_notification"
        android:layout_weight="1.0"
        android:background="?android:selectableItemBackground"
        android:padding="10.0dip"
        android:scaleType="fitCenter"
        android:src="@drawable/btn_playback_rew_jb_dark" />

    <ImageButton
        android:id="@+id/playpause"
        android:layout_width="0.0dip"
        android:layout_height="@dimen/play_controls_notification"
        android:layout_weight="1.0"
        android:background="?android:selectableItemBackground"
        android:padding="10.0dip"
        android:scaleType="fitCenter"
        android:src="@drawable/btn_playback_pause_jb_dark" />

    <ImageButton
        android:id="@+id/next"
        android:layout_width="0.0dip"
        android:layout_height="@dimen/play_controls_notification"
        android:layout_weight="1.0"
        android:background="?android:selectableItemBackground"
        android:padding="10.0dip"
        android:scaleType="fitCenter"
        android:src="@drawable/btn_playback_ff_jb_dark" />
</LinearLayout>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="1.0px"
    android:layout_above="@id/buttons"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/thumbnail"
    android:background="?android:dividerHorizontal" />

<ImageButton
    android:id="@+id/stop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="?android:selectableItemBackground"
    android:padding="8.0dip"
    android:src="@drawable/ic_close_notification_holo_dark" />

<LinearLayout
    android:id="@+id/textarea"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_gravity="center_vertical"
    android:layout_toLeftOf="@id/stop"
    android:layout_toRightOf="@id/thumbnail"
    android:orientation="vertical"
    android:paddingLeft="@dimen/notification_padding"
    android:paddingTop="8.0dip" >

    <TextView
        android:id="@+id/trackname"
        style="@android:style/TextAppearance.StatusBar.EventContent.Title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:focusable="true"
        android:singleLine="true" />

    <Chronometer
        android:id="@+id/duration"
        style="@android:style/TextAppearance.StatusBar.EventContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:ellipsize="marquee"
        android:layout_marginTop="6dp"
        android:fadingEdge="horizontal"
        android:maxLines="1" />

</LinearLayout>

2. notification.bigContentView assiginment RemoteView 2. notification.bigContentView assiginment RemoteView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在App Widget中制作类似于Google Play音乐小部件中的自定义视图? - How to make a custom view in an App Widget similar to the one in Google Play Music widget? 如何获得类似于Google Play音乐应用的专辑屏幕的滚动效果? - How to achieve a scroll effect similar to the Google Play Music app's album screen? 在应用中播放Google音乐中的歌曲 - Play song from Google Music in app Android-为Android创建音乐播放器(例如Google的Play音乐)? - Android - Create music player for android like Play Music from Google? 如何实现类似于Google Play音乐的导航抽屉选择器 - How to implement navigation drawer selector similar to Google Play Music 如果没有不断的通知,“Play Music”应用程序如何运行? - How does the 'Play Music' app run without constant notification? 如何从Google Play音乐访问媒体? - How to access media from Google Play Music? 如何在Android中通过通知播放音乐? - how to play a music by notification in android? 如何从Google Play创建动态应用 - how to create dynamic app from google play 如何创建“ Google Play音乐-队列界面”中使用的界面 - How to create the Interface used in “Google Play Music - Queue Interface”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM