Use of Notification to notify notification

Source: Internet
Author: User

Use of Notification to notify notification

Create a icationicationtest project and modify the code in activity_main.xml as follows:
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"

Android: orientation = "vertical">
<Button
Android: id = "@ + id/send_notice"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "Send notice"
/>
</LinearLayout>
The layout file is very simple. There is only one Send notice button in it to Send a notification. Next, modify
The code in MainActivity is as follows:
Public class MainActivity extends Activity implements OnClickListener {
Private Button sendNotice;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
SendNotice = (Button) findViewById (R. id. send_notice );
SendNotice. setOnClickListener (this );
}
@ Override
Public void onClick (View v ){
Switch (v. getId ()){
Case R. id. send_notice:
Icationicationmanager manager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE );
Notification notification = new Notification (R. drawable. ic_launcher, "This is ticker text", System. currentTimeMillis ());
Notification. setLatestEventInfo (this, "This is content title", "This is content text", null );
Manager. Y (1, notification );
Break;
Default:
Break;
}
}

}

Related Article

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.