1. publicclassMainActivityextendsActivity{
  2. privateButtonshow;
  3. privatePendingIntentcontentIntent;
  4. privateIntentintent;
  5. privateNotificationManagermanager;
  6. privateNotificationnotification;
  7. @Override
  8. protectedvoidonCreate(BundlesavedInstanceState){
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11. intent=newIntent(Intent.ACTION_VIEW);
  12. intent.setType("vnd.android-dir/mms-sms");
  13. contentIntent=PendingIntent.getActivity(getApplicationContext(),0,intent,0);
  14. //1.notification进行提示(一闪而过的)时候的图片,提示,以及时间(一般设为当前时间)
  15. notification=newNotification(R.drawable.ic_launcher,"有新消息",System.currentTimeMillis());
  16. //2.设置下拉statusbar出现的notification标题和具体内容,以及点击notification进行跳转的pendingIntent
  17. notification.setLatestEventInfo(getApplicationContext(),"10086","尊敬的用户您好,最近....",contentIntent);
  18. //3.实例化NotificationManager
  19. manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  20. show=(Button)findViewById(R.id.button);
  21. show.setOnClickListener(newView.OnClickListener(){
  22. @Override
  23. publicvoidonClick(Viewv){
  24. //4.设置要唤醒的notification的id
  25. manager.notify(0,notification);
  26. }
  27. });
  28. }
  29. }

更多相关文章

  1. Android(安卓)如何让程序定时进行消息通知到通知栏
  2. Android设置重复文字水印背景
  3. android列表为空时提示语
  4. 如何为Android(安卓)Activity设置背景图片?
  5. View的XML 属性大全(官方文档)
  6. Android(安卓)各种音量的获取和设置
  7. Android中全屏无标题设置
  8. Android(安卓)修改系统时间代码
  9. Android(安卓)-- 文字设置超链接

随机推荐

  1. Android客户端与后台服务器的数据交互
  2. 开发者必看|Android(安卓)8.0 新特性及开
  3. Android(安卓)控件之 Spinner下拉列表 使
  4. React Native添加Android原生模块
  5. android 机器人
  6. 浅析Android下的Android.mk文件
  7. Android事件分发机制完全解析,带你从源码
  8. Study on Android【一】--概述
  9. android简介
  10. Android(安卓)ANR错误排查