导入support- -v4
1.进入 file-project structure
2.左边选择app
3.右边选择dependencies
4.左下角可以看到一个加号,点击选择Library dependency就可以看到可以导入的jar包,选择support-v4导入即可
简单通知
通知管理工具
`NotificationManager manager= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);通知对象
Notification notification = new NotificationCompat.Builder(MainActivity.this,"default") .setContentTitle("title") .setContentText("text") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)) .build();
显示通知
manager.notify(1,notification);
通知的点击功能
- Intent intent = new Intent(MainActivity.this,NotificationActivity.class);
- PendingIntent pendingIntent =PendingIntent.getActivity(MainActivity.this,0,intent,0);
Notification notification = new NotificationCompat.Builder(MainActivity.this,"default")
.setContentTitle("title")
.setContentText("text")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setContentIntent(pendingIntent)//点击功能
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_MAX)
.build();