zoukankan      html  css  js  c++  java
  • Notification小案例

    xml文件:

    <Button

            android:onClick="click"

            android:layout_width="wrap_content"

            android:layout_centerHorizontal="true"

            android:layout_centerVertical="true"

            android:layout_height="wrap_content"

            android:text="显示通知" />

    MainActivity类中:

            @SuppressLint("NewApi")

            public void click(View view){

                //1.获取到手机系统里面的通知管理器

                NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                

                //2.实例化notification表示通知的具体内容

                Notification notification = new Notification(R.drawable.ic_launcher, "我是一个notification", System.currentTimeMillis());

               

                notification.flags = Notification.FLAG_INSISTENT;//永远存在

                Intent intent = new Intent();

                intent.setAction(Intent.ACTION_CALL);

                intent.setData(Uri.parse("tel:110"));

                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

                notification.setLatestEventInfo(this, "我是notification标题", "我是notification的文本", pendingIntent);

               

               

                //新的API

                /*Notification.Builder builder = new Builder(this);

                builder.setContentTitle("我是notification的标题")

                .setContentText("我是notification的内容")

                .setSmallIcon(R.drawable.ic_launcher)

                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));

                Notification notification = builder.build();*/

                nm.notify(0, notification);

               

            }

    清单文件中:

    <uses-permission android:name="android.permission.CALL_PHONE"/>

  • 相关阅读:
    upgrade和update的区别
    批处理文件的几种路径扩展
    CMD does not support UNC paths as current directories.的巧妙解决方案
    让批处理不回显错误信息
    python中那纠结的os.system()与空格处理
    jQuery Mobel 学习相关资料整理(一)
    c#获取某月的第一天和某月的最后一天
    Umbraco网站制作(七) 调用外部用户控件
    Umbraco网站制作(八) 实现伪静态
    Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。
  • 原文地址:https://www.cnblogs.com/changyinlu/p/4937825.html
Copyright © 2011-2022 走看看