//1、创建一个自定义的消息布局 view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/image" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_marginRight="10dp" />
<TextView android:id="@+id/text" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textColor="#000" />
</LinearLayout>
//2、在程序代码中使用RemoteViews的方法来定义image和text。然后把RemoteViews对象传到contentView字段
RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.view);
contentView.setImageViewResource(R.id.image,R.drawable.icon);
contentView.setTextViewText(R.id.text,”Hello,this message is in a custom expanded view”);
notification.contentView = contentView;
//3、为Notification的contentIntent字段定义一个Intent(注意,使用自定义View不需要setLatestEventInfo()方法)
Intent notificationIntent = new Intent(this,Main.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.contentIntent = contentIntent;
//4、发送通知
mNotificationManager.notify(2,notification);
//以下是全部示例代码
//创建一个NotificationManager的引用
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);
//定义Notification的各种属性
int icon = R.drawable.icon; //通知图标
CharSequence tickerText = "Hello"; //状态栏显示的通知文本提示
long when = System.currentTimeMillis(); //通知产生的时间,会在通知信息里显示
//用上面的属性初始化Nofification
Notification notification = new Notification(icon,tickerText,when);
RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.view);
contentView.setImageViewResource(R.id.image, R.drawable.iconempty);
contentView.setTextViewText(R.id.text, "Hello,this is JC");
notification.contentView = contentView;
Intent notificationIntent = new Intent(this,Main.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.contentIntent = contentIntent;
//把Notification传递给NotificationManager
mNotificationManager.notify(0,notification);
|
相关推荐
android 状态栏的图标与文字提醒 NotificationManager与Notification
首先,发送一个状态栏通知必须用到两个类:NotificationManager、Notification。 NotificationManager:是状态栏通知的管理类,负责发通知、清楚通知等。 NotificationManager是一个系统Service,必须通过...
调用getSystemService(NOTIFICATION_SERVICE)方法获取系统的NotifacationManager服务 通过构造器创建一个Notification对象 为Notification设置各种属性 通过NotificationManager发送Notification。
首先,发送一个状态栏通知必须用到两个类: NotificationManager 、 Notification。 NotificationManager : 是状态栏通知的管理类,负责发通知、清楚通知等。 NotificationManager 是一个系统Service,必须通过 ...
自学 Android 做的第二十七个 Android 程序,使用了 NotificationManager、Notification 和 Notification.Builder
NULL 博文链接:https://forlan.iteye.com/blog/2264722
这个例子演示Android 在状态栏... NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, myNotification);//发送Notification
本文主要讲解状态栏通知Notification、NotificationManager,小编觉得非常详细,给大家一个参考,希望对大家学习有所帮助。
可以设置一条通知,当然可以更新一条通知,我们通过在调用NotificationManager.notify(ID, notification)时所使用的ID来更新它。为了更新你之前发布的通知,你需要更新或者创建一个NotificationCompat.Builder对象,...
本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动、灯光、声音等效果,分享给大家供大家参考,具体内容如下 效果图: MainActivity: import java.io.File; import android....
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, notification); or Json2Notification.from(context)....
要使用消息通知,必须要用到两个类:NotificationManager和Notification,其他NotificationManager的初始化是用getSystemService方法,并且通过notify方法来向android系统发送消息栏通知和显示。效果 :代码: 代码...
在使用手机时,当有未接来电或者新短消息时,手机会给...使用Notification和NotificationManager类发送和显示通知也比较简单,大致可以分为以下四个步骤 (1)调用getSystemService() 方法获取系统的NotificationManag
在使用手机时,当有未接来电或者是新短消息时,手机会给出...使用Notification和NotificationManager类发送和显示通知也比较简单,大致可分为以下4个步骤。 (1)调用getSystemService()方法获取系统的NotificationManag
notification类表示一个持久的通知,将提交给用户使用NotificationManager。已添加的Notification.Builder,使其更容易构建通知。
关于通知Notification相信大家都不陌生了,平时上QQ的时候有消息来了或者有收到了短信,手机顶部就会显示有新消息什么的,就类似这种。今天就稍微记录下几种Notification...3.0以前的通知和3.0以后的通知是有些区别的。
这个自动检测升级Apk的功能,相信每个应用都会使用到。...其中使用Service、BroadcastReceiver、OkHttp下载、Gson解析json、NotificationManager、Notification 运用的知识也挺多的,也可以功大家学习使用。
Android界面 NotificationManager使用Bitmap做图标,如何实现呢,本文将介绍解决方法,需要的朋友可以参考下
Notification可以理解为通知的意思一般用来显示广播信息 用Notification就必须要用到NotificationManager 想用Notification一般有三个步骤,如下所示 ① 一般获得系统级的服务NotificationManager。 调用Context....