Android Notification用法
2014-09-16 14:25
141 查看
package com.example.notificationtest; import android.os.Bundle; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.view.Menu; import android.view.View; public class NotificationTestActivity extends Activity { static final int NOTIFICATION_ID = 0x123; NotificationManager nm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification_test); nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.notification_test, menu); return true; } public void send(View Source) { Intent intent = new Intent(NotificationTestActivity.this, OtherActivity.class); PendingIntent pi = PendingIntent.getActivity(NotificationTestActivity.this, 0, intent, 0); Notification notify = new Notification.Builder(this) .setAutoCancel(true) .setTicker("有新消息") .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("一条新通知") .setContentText("恭喜你,您加薪了!") .setWhen(System.currentTimeMillis()) .setContentIntent(pi) .build(); nm.notify(NOTIFICATION_ID,notify); } public void del(View v) { nm.cancel(NOTIFICATION_ID); } }
相关文章推荐
- android notification的用法
- Android --- (5)intent对象更多用法,目录说明,打印Notification
- Android之Notification的多种用法
- android中关于notification的最新用法
- Android编程开发之NotiFication用法详解
- Android Notification 用法
- 【Android】15.4 例15-2--Notification基本用法
- Android之Notification的多种用法
- Android之Notification的多种用法(转)
- Android中Notification的用法汇总
- android应用开发揭秘之Notification的简单用法
- android中Notification功能和用法(状态栏通知)
- Android Notification的用法及步骤
- Android之Notification的推荐用法
- Android关于notification的在不同API下的用法说明
- Android的Notification的用法
- Android Notification的作用和用法
- Android 通过系统使用NotificationListenerService 监听各种Notification的用法
- Android中Notification用法实例总结
- Android API Level在11前后及16之后时Notification的不同用法