1.Notification(状态栏通知)的学习
关键代码:
private Context mContext;
private NotificationManager mNManager;
private Notification notify1;
Bitmap LargeBitmap = null;
private static final int NOTIFYID_1 = 1;
private Button btn_show_normal;
private Button btn_close_normal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = MainActivity.this;
//创建大图标的Bitmap
LargeBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.iv_lc_icon);
mNManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
bindView();
}
private void bindView() {
btn_show_normal = (Button) findViewById(R.id.btn_show_normal);
btn_close_normal = (Button) findViewById(R.id.btn_close_normal);
btn_show_normal.setOnClickListener(this);
btn_close_normal.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_show_normal:
//定义一个PendingIntent点击Notification后启动一个Activity
Intent it = new Intent(mContext, OtherActivity.class);
PendingIntent pit = PendingIntent.getActivity(mContext, 0, it, 0);
//设置图片,通知标题,发送时间,提示方式等属性
Notification.Builder mBuilder =