android之Notification
来源:互联网 发布:mac暴风影音删除不了 编辑:程序博客网 时间:2024/06/05 15:25
Notification为android中的通知,是在android桌面上方的状态栏中显示的提示信息,显示时不会影响用户的操作,同时Notification提供了各种不同的风格,可以显示文字、图像或按钮,只要用户不清楚Notificaion,Notification将永久的保留在手机的状态栏中。Notification中常用的几个对象如下:
NotificationManager 用于管理Notification,是用于处理系统通知的服务
Notification属于通知,可以设置其图标、标题以及内容,也可以自定义Notification 的UI。
PendingIntent名为预处理意图,用于处理点击通知后的跳转对象的封装。下面我们将用实际的代码来讲解一下:
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
用于获取系统通知服务,实例代码如下:
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity{
privatestatic final int NOTIFICAITON_ID = 0;
privateButton btnSend;
privateNotificationManager notificationManager;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.btnSend= (Button) findViewById(R.id.btnSend);
this.btnSend.setOnClickListener(clickListener);
this.notificationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
OnClickListenerclickListener = new OnClickListener() {
@Override
publicvoid onClick(View arg0) {
Intentintent = new Intent(MainActivity.this, PendingIntentActivity.class);
PendingIntentpendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
Notificationnotification = new Notification(R.drawable.ic_launcher, "通知。。。。", System.currentTimeMillis());
notification.setLatestEventInfo(MainActivity.this,"标题", "详细内容。。。。", pendingIntent);
notificationManager.notify(NOTIFICAITON_ID,notification);
}
};
}
以上纯属个人笔记,以方便以后查看,如果各位大牛们有何指点,还请赐教!多交流!
- Android 之 Notification
- android之Notification通知
- Android 之 Notification
- android之Notification通知
- Android学习之Notification
- Android之Notification
- android之Notification实现
- Android开发之Notification
- android之Notification通知
- Android之Notification
- Android之基础Notification
- android之Notification通知
- android之Notification通知
- android之Notification通知
- Android之Notification通知
- android之Notification通知
- android之Notification
- android之Notification通知
- 音频采样
- 比较两个文件内容间的不同之处
- VS2008中OGRE1.7.4下配置Hydrax-v0.5.1插件
- Windows 2003 从Oracle 9201 update to 9208
- 中文乱码解决大全
- android之Notification
- msensor-hal-crash
- 可以编辑的DataGridViewComboBoxColumn
- Visual.Assist.X.V10.7.1929的Crack破解补丁.新增5项特性,修正30余处bug. 2013.02.22(Release)
- MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- 异步更新ProgressBar(使用AsyncTask)
- servlet各版本区别以及dynamic web module 版本之间的区别
- 2013腾讯编程马拉松初赛第0场(3月20日)HDU 4502
- java创建动态代理类