Google

2013-01-24 17 views
13

से Play Music ऐप के समान अधिसूचना कैसे बनाएं, मैं एक ऐसी सूचना बनाने की कोशिश कर रहा हूं जो Google के "Play Music" ऐप के समान ही है।Google

Play Music app notification

कुछ सवाल है कि उम्मीद है कि किसी को जवाब कर सकते हैं।

  1. क्या यह अधिसूचना कस्टम रिमोट व्यू के साथ की गई है?
  2. क्या एक्स अधिसूचना कॉम्पेट.बिल्डर एपीआई के विजेट हिस्से को बंद करने के लिए एक्स है? या बस कस्टम रिमोट व्यू का हिस्सा?
  3. यदि यह सभी कस्टम विचार हैं तो मैं न्यूनतम और अधिकतम राज्यों के लिए कस्टम रिमोट व्यू कैसे सेट कर सकता हूं?

उत्तर

10

हां, यह सब कस्टम RemoteViews के साथ किया जाता है। आप Notification के लिए दस्तावेज़ों में देखेंगे, के साथ contentView के साथ एक फ़ील्ड है।

+2

आपकी प्रतिक्रिया के लिए धन्यवाद। मुझे तब तक थोड़ा गड़बड़ कर लिया जब तक मुझे पता चला कि मुझे पहले अधिसूचना बनाना था और फिर मैं bigContentView सेट कर सकता था। – Jona

+0

@ कबाबू मुझे एक सुझाव देता है। मैं इस लिंक की तरह प्ले/पॉज़ को नियंत्रित करने के लिए रिमोट व्यू का उपयोग करके एक अधिसूचना बड़ा दृश्य बनाता हूं (http://stackoverflow.com/questions/14508369/how-to-create-a-notification-similar-to-play-music-app-from -google) सभी सही हैं लेकिन जब मैं डिवाइस से बैक बटन पर क्लिक करता हूं और एप्लिकेशन से बाहर क्लिक करता हूं तो ईवेंट (प्ले/पॉज़/फॉरवर्ड/क्लोज़) बटन काम नहीं करता है। कृपया मेरी मदद करें। –

+0

@HelalKhan अधिक जानकारी के साथ एक नया प्रश्न बनाने के लिए स्वतंत्र महसूस करें। यद्यपि यहां टिप्पणियां उस के लिए सही जगह नहीं हैं। – kabuko

1
  1. रेस में statusbar_expanded.xml बनाने/लेआउट-v16/

<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

+0

सुझाव की आवश्यकता है।सभी सही हैं, लेकिन जब मैं डिवाइस से बैक बटन पर क्लिक करता हूं और एप्लिकेशन से बाहर होता हूं तो ईवेंट पर क्लिक करें (प्ले/पॉज़/फॉरवर्ड/क्लोज़) बटन काम नहीं करता है। कृपया मेरी मदद करें। –

+0

शैली = "@ एंड्रॉइड: शैली/टेक्स्टएपियरेंस.स्टैटसबार.इवेंटकंटेंट टिटल" धन्यवाद मेरे दोस्त के लिए अंगूठे ऊपर। लव यू – AlAsiri

4

मैं जानता हूँ कि मैं बहुत देर से कर रहा हूँ जवाब, लेकिन यह मीडिया अधिसूचनाओं को आजमाने वाले नए लोगों के लिए है।

  1. RemoteViews का उपयोग करने की कोई आवश्यकता नहीं है। अब हम NotificationCompat.MediaStyle() का उपयोग कर सकते हैं। यह आवश्यकतानुसार पूरी तरह से काम करता है, और Media उपभोग अनुभव में एकरूपता लाता है।

  2. मीडिया स्टाइल अधिसूचनाओं का उपयोग करते समय संस्करण> लॉलीपॉप के लिए कोई एक्स बटन नहीं होगा। इसके बजाय हम रोके गए राज्य में अधिसूचना को खारिज कर देते हैं। ऐसे मामलों में पालन करने की प्रक्रिया इस link में दिखाया गया है।

  3. मीडिया स्टाइल अधिसूचना setShowActionsInCompactView() को परिभाषित करने के लिए है कि सभी कार्यों को कॉम्पैक्ट मोड में दिखाया जाए।

    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); 
    

इस रूप में की जरूरत पूरी मीडिया अधिसूचना स्थापित करने में मदद करना चाहिए: निम्नलिखित एक टुकड़ा है। हैप्पी कोडिंग!