看黑马安卓基础教学视频总结(通知栏&反编译&Fragment)

1.通知(★★★

通知用于在状态栏显示消息,消息到来时以图标方式表示,如果需要查看消息,可以拖动状态栏到屏幕下方即可查看消息,在Android中通过通知管理器NotificationManager来发出或关闭一个通知。

使用步骤:

1.    获取通知管理器对象

private NotificationManager manager;//通知管理器

//获取通知管理器服务

manager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);


2.    如何发出一个通知

public void notify(View view) {

//方式一:链式调用
/* Notification noti = new Notification.Builder(this)
        .setContentTitle("我是大标题")
        .setContentText("我是标题的内容")
        .setSmallIcon(R.drawable.ic_launcher)
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
        .build();

manager.notify(1,noti ) ;

*/

      //方式二: 创建一个通知

      Notificationnotification = new Notification(R.drawable.ic_launcher,// 消息的图标

            "您有一条来自黑马程序员的通知", // 消息的标题

            System.currentTimeMillis());// 消息发送的时刻立即发送

      // 定义一个隐式意图:指定点击通知时要打开的Activity

      Intentintent = newIntent();

      intent.setAction("com.itheima.noftify");

      /*

       * PendingIntent

       * 是延时意图,在未来某个时间开启一个界面,并且可以指定使用的次数,其实就是对Intent进行的一个包装,并且指定了使用次数

       */

PendingIntentpendingIntent = PendingIntent.getActivity(this, 100,intent, PendingIntent.FLAG_ONE_SHOT);

      //设置消息的内容和意图

      notification.setLatestEventInfo(this, "这是详细通知的标题", "这是通知的详细内容", pendingIntent);

      //设置通知点击后自动关闭

      notification.flags =Notification.FLAG_AUTO_CANCEL;

      //设置消息发送时开启灯光、声音、震动等特效,如果震动开启了需要设置权限

      notification.defaults =Notification.DEFAULT_ALL</

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值