android中Notification的使用
16lz
2022-04-20
- publicclassMainActivityextendsActivity{
- privateButtonshow;
- privatePendingIntentcontentIntent;
- privateIntentintent;
- privateNotificationManagermanager;
- privateNotificationnotification;
- @Override
- protectedvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- intent=newIntent(Intent.ACTION_VIEW);
- intent.setType("vnd.android-dir/mms-sms");
- contentIntent=PendingIntent.getActivity(getApplicationContext(),0,intent,0);
- //1.notification进行提示(一闪而过的)时候的图片,提示,以及时间(一般设为当前时间)
- notification=newNotification(R.drawable.ic_launcher,"有新消息",System.currentTimeMillis());
- //2.设置下拉statusbar出现的notification标题和具体内容,以及点击notification进行跳转的pendingIntent
- notification.setLatestEventInfo(getApplicationContext(),"10086","尊敬的用户您好,最近....",contentIntent);
- //3.实例化NotificationManager
- manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- show=(Button)findViewById(R.id.button);
- show.setOnClickListener(newView.OnClickListener(){
- @Override
- publicvoidonClick(Viewv){
- //4.设置要唤醒的notification的id
- manager.notify(0,notification);
- }
- });
- }
- }
更多相关文章
- Android(安卓)如何让程序定时进行消息通知到通知栏
- Android设置重复文字水印背景
- android列表为空时提示语
- 如何为Android(安卓)Activity设置背景图片?
- View的XML 属性大全(官方文档)
- Android(安卓)各种音量的获取和设置
- Android中全屏无标题设置
- Android(安卓)修改系统时间代码
- Android(安卓)-- 文字设置超链接