zoukankan      html  css  js  c++  java
  • Android Wear创建一个通知

    创建Android Wear的通知实际上和手机上创建没啥区别,主要是多了几个新类,只要用熟悉了一切都好办了。(如果只是测试通知,则直接运行wear app就能够看到效果)

    创建一个简单的wear通知分为3步:

    一、创建一个Intent用于设置你要做的动作

    二、创建一个PendingIntent把Intent放进去(主要是根据intent传入的内容做跳转动作)

    三、创建一个NotificationCompat.Builder用于设置通知内容,例如:将PendingIntent传递进去用于action的点击跳转,设置通知内容、设置通知标题、设置通知图标等

    四、创建一个NotificationManagerCompat实例并调用notify()方法将通知发送出去

    下面是实例代码:

    1.创建一个通知

    public void showNotification(Context context) {
            int notificationId = 001;
            Intent intent = new Intent();
            intent.setClass(context, ViewNotificationActivity.class);
            //传递数值
            //viewIntent.putExtra(EXTRA_EVENT_ID, eventId);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)//设置notification小图标
                    .setContentTitle("这是一个标题")//设置notification标题
                    .setContentText("这是内容")//设置notification文本内容
                    .setContentIntent(pendingIntent);//设置点击设置点击action时要跳转的页面(wear设备向左滑动第二个按钮的点击后所做的操作)
    
            //创建一个notifaicationmanamgercompat实例
            NotificationManagerCompat manager = NotificationManagerCompat.from(context);
            //将通知发送出去
            manager.notify(notificationId, builder.build());
        }
    

    2.将上述通知在wear app项目中的主方法中调用运行即可

  • 相关阅读:
    poj 3125 Printer Queue(STL注意事项)
    poj 2823 Sliding Window (STL超时版)
    poj 1088 滑雪 详解
    poj 2983 Is the Information Reliable?
    poj 2524 Ubiquitous Religions (STL与非STL的对比)
    高精度算法集合
    zTree v2.6 v3.0 初始化 / 方法对比
    下面是关于rownum的介绍(oracle)
    web性能优化
    jQueryEasyui,DataGrid几个常用的操作
  • 原文地址:https://www.cnblogs.com/tony-yang-flutter/p/5109027.html
Copyright © 2011-2022 走看看