notification的使用
来源:互联网 发布:mac怎么打开mpp文件 编辑:程序博客网 时间:2024/05/18 05:11
notification的使用
1.获取到一个notification服务
2.准备一个notification的信息
3.准备notification的具体信息和点击事件
4.把构建的notification传给notification管理器
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void click(View view){
//1.获取到一个 notification的服务
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
//2 .准备一个notification的信息
Notification notification = new Notification(R.drawable.notification, "我是notification", System.currentTimeMillis());
//3. 准备notification的具体信息 和 点击事件
notification.flags=Notification.FLAG_NO_CLEAR;//设置点击"清除"的操作
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:110"));
//延期的意图
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "我是title", "我是文本", contentIntent);
//4.把我们构建的notification传个notification管理器
manager.notify(0, notification);
}
//自定义一个notification
public void click1(View view){
//1.获取到一个 notification的服务
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
// 远程的view
Notification notification = new Notification();
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.noti); //要准备一个notification的布局文件
rv.setTextViewText(R.id.text, "text"); //给远程的控件设置属性.使用到进程间的通信
rv.setTextViewText(R.id.title, "title");
//2.创建一个显示的notification
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:110"));
//延期的意图
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
//3.指定显示的内容
notification.contentView = rv;
notification.contentIntent = contentIntent;
notification.icon = R.drawable.notification;
notification.tickerText="haha";
notification.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(0, notification);
}
}
- 3. Notification的使用
- 3、Notification的使用
- Android-Notification的使用
- Android Notification的使用
- android Notification 的使用
- android Notification 的使用
- Android Notification 的使用
- Android-Notification的使用
- android Notification 的使用
- 使用自定义的 Notification
- Notification的使用详解
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- Notification 的使用
- android Notification 的使用
- android Notification的使用
- Notification的使用
- 周鸿祎微博乌龙暴露360搜索安全堪忧
- 黑马程序员_HashSet集合
- 360搜索带来什么裂变效应
- ARM微处理器的uC/OS的移植设计
- New start
- notification的使用
- 黑客专家教你如何设计不易破解的密码
- Spring MVC 与 Hibernate 实现注册功能
- 不出站换车就是好
- java的路径全接触
- Linux系统优化部分内核参数调优中文注释
- 我使用过的Linux命令系列总目录
- Service的两种启动方式
- 蓝色理想中[AS3] 教程集合