zoukankan      html  css  js  c++  java
  • android notification 理解

    notification简单使用

    1.不推荐 , 已不使用

     NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.ic_launcher, "This is ticker text", System.currentTimeMillis());
        Intent intent = new Intent(this, NotificationActivity.class);
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent,
        PendingIntent.FLAG_CANCEL_CURRENT);
        //被删除
        notification.setLatestEventInfo(this, "This is content title","This is content text", pi);
        manager.notify(1, notification);
    

       2.系统推荐
      

     NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            Intent intent = new Intent(this, DD.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
            Notification notification = new NotificationCompat.Builder(this)
                    .setSmallIcon(android.R.drawable.sym_def_app_icon)    //图标
                    .setContentTitle("标题")
                    .setContentInfo("右下角")
                    .setContentText("内容")
                    .setAutoCancel(true)    //点击一下就消失
                    .setContentIntent(pendingIntent)   //延迟意图
                    .setTicker("刚出来是在手机最上方显示,一会就消失")
                    .setWhen(System.currentTimeMillis())    //消息的时间
                    .build();   //创建notification
    //        notification.flags = Notification.FLAG_AUTO_CANCEL;      跟setAutoCancel一样作用
            //显示notification  第一个参数不能重复,否则就只能显示重复的最后一个notification
            manager.notify(1,notification);
    

    3. 自定义notification
      

     RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.activity_main);
        remoteViews.setImageViewResource(R.id.imageView,android.R.drawable.sym_def_app_icon);
        remoteViews.setTextViewText(R.id.textText,"textview 的内容");
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Intent intent = new Intent(this, DD.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        Notification notification = new NotificationCompat.Builder(this)
                .setAutoCancel(true)    //点击一下就消失
                .setContentIntent(pendingIntent)   //延迟意图
                .setContent(remoteViews)     //设置自定义的view
                .build();
        manager.notify(1,notification);
    
  • 相关阅读:
    俄罗斯方块源码解析(带下载)[2]
    gridView基本操作
    俄罗斯方块源码解析 系列 更新
    俄罗斯方块源码解析(带下载)[1]
    《CLR Via C#》 学习心得一 CLR基础知识
    《CLR Via C#》 学习心得之二 类型基础
    《CLR Via C#》 学习心得之三 基元类型、引用类型和值类型
    观《大话设计模式》之——简单工厂模式
    观Fish Li《细说 Form (表单)》有感
    总结做了八个月asp.net程序员
  • 原文地址:https://www.cnblogs.com/IT-lss/p/5696938.html
Copyright © 2011-2022 走看看