public class MainActivity extends Activity {private NotificationManager notificationManager;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);}public void test1(View v){//Toast.makeText(this, "点击我了", Toast.LENGTH_LONG).show();showNotification("来短信了", "5554", "I love you", R.drawable.ic_launcher, R.drawable.ic_launcher);}public void showNotification(String tickerText,String contentTitle,String contentText,int iconId,int notiId){//2步创建一个NotificationNotification notification = new Notification();//设置通知 消息  图标notification.icon=iconId;//设置发出消息的内容notification.tickerText=tickerText;//设置发出通知的时间notification.when=System.currentTimeMillis();//设置显示通知时的默认的发声、振动、Light效果notification.defaults = Notification.DEFAULT_VIBRATE;//振动//Notification notification = new Notification(R.drawable.ic_launcher, "有新的消息", System.currentTimeMillis());//3步:PendingIntent  android系统负责维护PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, getIntent(), 0);//4步:设置更加详细的信息notification.setLatestEventInfo(this, contentTitle, contentText, pendingIntent);//5步:使用notificationManager对象的notify方法 显示Notification消息   需要制定 Notification的标识notificationManager.notify(notiId, notification);}public void clearNoti(View v){notificationManager.cancelAll();//清除所有}}

更多相关文章

  1. Android(安卓)RecyclerView 分割线(DividerItemDecoration )
  2. Android点击效果加边框
  3. 在Android(安卓)WebView中设置Cookie
  4. Android(安卓)自定义ProgressBar--进度自己设置图片
  5. Android(安卓)Studio 自带的侧滑布局设置
  6. android webview无网络情况下的处理
  7. android使用webview加载网页
  8. Android(安卓)UI控件详解-Gallery(画廊)
  9. Android(安卓)UI控件详解-ImageSwitcher(图片切换器)

随机推荐

  1. TabHost自定义标签页(二)
  2. Android 触摸屏手势识别资料汇总
  3. Android学习杂记(二):异步任务AsyncTask详解
  4. Android Api WindowManager.LayoutParams
  5. FloatingActionButton
  6. The method Inflate() in android
  7. Android HAL实例解析
  8. Android基础篇——创建一个Android工程
  9. Android监控软键盘变化实例
  10. 【Android】【绘图】绘制波浪线动画