Introduction to Android Notification-android Learning Journey (41)

Source: Internet
Author: User
<span id="Label3"></p>Notification Introduction<p><p>Notification is located on the top of the mobile phone, used to display a variety of information on the phone, including network status, battery status, time and so On.</p></p>Property Method Introduction<p><p></p></p>code example<pre class="prettyprint"><code class=" hljs java"><span class="hljs-keyword"><span class="hljs-keyword"></span> package</span>peng.liu.test;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.app.Activity;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.app.Notification;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.app.NotificationManager;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.app.PendingIntent;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.app.TabActivity;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.content.Intent;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.os.Bundle;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.view.View;<span class="hljs-keyword"><span class="hljs-keyword">Import</span></span>android.widget.TabHost;<span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-class"><span class="hljs-class"> <span class="hljs-keyword">class</span> <span class="hljs-title">mainactivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Activity</span> {</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Static</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Final</span></span> <span class="hljs-keyword"><span class="hljs-keyword">int</span></span>notification__id =<span class="hljs-number"><span class="hljs-number">0X123</span></span>; Notificationmanager nm;<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">onCreate</span></span>(Bundle Savedinstancestate) {<span class="hljs-keyword"><span class="hljs-keyword">Super</span></span>. onCreate (savedinstancestate); Setcontentview (r.layout.activity_main); NM = (notificationmanager) Getsystemservice (notification_service); }<span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">Send</span></span>(view View) {Intent Intent =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Intent (mainactivity.<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>, mainactivity2.class); pendingintent pi = pendingintent.getactivity (mainactivity.<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>,<span class="hljs-number"><span class="hljs-number">0</span></span>, intent,<span class="hljs-number"><span class="hljs-number">0</span></span>); Notification Notification =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Notification.builder (<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>). Setautocancel (<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>). Setticker (<span class="hljs-string"><span class="hljs-string">"new message"</span></span>). Setsmallicon (r.drawable.ic_launcher). Setcontenttitle (<span class="hljs-string"><span class="hljs-string">"new message"</span></span>). Setcontenttext (<span class="hljs-string"><span class="hljs-string">"hello world"</span></span>). SetDefaults (notification.default_sound| notification.default_lights). setwhen (system.currenttimemillis ()). setcontentintent (pi) . Build (); Nm.notify (notification__id,notification); }<span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">Dev</span></span>(view View) {nm.cancel (notification__id); }}</code></pre><pre class="prettyprint"><code class=" hljs xml"><span class="hljs-pi"><span class="hljs-pi"><?xml version= "1.0" encoding= "utf-8"?></span></span><span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">linearlayout</span> <span class="hljs-attribute">xmlns:android</span>=<span class="hljs-value">"http://schemas.android.com/apk/res/android"</span> <span class="hljs-attribute"> Xmlns:tools</span>=<span class="hljs-value">"http://schemas.android.com/tools"</span><span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"match_parent" </span> <span class="hljs-attribute">android:layout_height</span>=<span class="hljs-value">"match_parent"</span><span class="hljs-attribute">android:orientation</span>=<span class="hljs-value">"vertical" </span>> </span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">button </span> <span class="hljs-attribute">android:layout_ Width </span> =<span class="hljs-value"> "wrap_content" </span> <span class="hljs-attribute">android:layout_height< /span>=<span class="hljs-value"> "wrap_content" </span> <span class="hljs-attribute">android:text </span> =<span class="hljs-value"> "New button" </span> <span class="hljs-attribute">android:id </span> =<span class="hljs-value"> " @+id/button "</span> <span class=" hljs-attribute ">android:onclick </span> =<span class=" hljs-value ">" send "</span>/ </span></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">button</span><span class="hljs-attribute">android:layout_width</span>=<span class="hljs-value">"wrap_content"</span><span class="hljs-attribute">android:layout_height</span>= <span class="hljs-value">"wrap_content"</span> <span class="hljs-attribute">android:text</span>= "<span class="hljs-value">New button"</span><span class="hljs-attribute">android:id</span>=<span class="hljs-value">"@+id/button2"</span><span class="hljs-attribute">Android:onclick </span>=<span class="hljs-value">"dev"</span>/> </span></span><span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">linearlayout</span>></span></span></code></pre> <p><p>Introduction to Android Notification-android Learning Journey (41)</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.