Notification通知栏的基本使用

来源:互联网 发布:js表单数据的验证 编辑:程序博客网 时间:2024/06/01 07:55
public class MainActivity extends AppCompatActivity { Intent intent = new Intent(MainActivity.this,NotificationActivity.class);                PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,intent,0);//这里的第一个是Contex,第二个是请求码,第三个是意图对象,第四个是标记,一般第二和第四我们是用不上的,所以一般都是传0                NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);                Notification notification = new NotificationCompat.Builder(MainActivity.this)                        .setContentTitle("This is content title")//设置标题                        .setContentText("This is content text")//设置内容                        .setWhen(System.currentTimeMillis())//设置时间                        .setSmallIcon(R.mipmap.ic_launcher)//设置最小的图标                        .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ma))//设置显示框的图标                        .setContentIntent(pi)//设置点击的动作                        .setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Orion.ogg")))//设置通知的声音                        .setVibrate(new long[]{0,1000,1000,1000})//设置消息的震动,第一个参数是消息来时静止时间,第二个是震动时间,第三个是静止时间,第四个是震动时间                        .setLights(Color.GREEN,1000,1000)//设置消息通知灯的颜色,第一个是颜色,第二个是灯亮的时间,第三个是灯灭的时间                        .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)))//设置消息通知显示大图片//                        .setStyle(new NotificationCompat.BigTextStyle().bigText("Learn how to build notifications,send and sync data,and use voice actions. Get the official Android IDE and developer tools to build apps for Android."))//设置消息显示大文本                        .setPriority(NotificationCompat.PRIORITY_MAX)//设置消息显示的优先级//                      .setAutoCancel(true)//设置消息点击之后被自动清除                        .build();                manager.notify(1,notification);//设置消息,第一个是消息通知的ID,要保证其的唯一性,第二个是notification对象                }
阅读全文
0 0
原创粉丝点击