- 填充想要展示的内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int smallIcon = R.drawable.tb_bigicon;
String ticker = "您有一条新通知";
String title = "双十一大优惠!!!";
String content = "仿真皮肤充气娃娃,女朋友带回家!";
- 实例化工具类,并且调用对应方法即可
NotifyUtil notify1 = new NotifyUtil(mContext, 1);
notify1.notify_normal_singline(pIntent, smallIcon, ticker, title, content, true, true, false);
- 淘宝样式:普通类型通知(单行)
/**
* 高仿淘宝
*/
private void notify_normal_singLine() {
//设置想要展示的数据内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int smallIcon = R.drawable.tb_bigicon;
String ticker = "您有一条新通知";
String title = "双十一大优惠!!!";
String content = "仿真皮肤充气娃娃,女朋友带回家!";
//实例化工具类,并且调用接口
NotifyUtil notify1 = new NotifyUtil(mContext, 1);
notify1.notify_normal_singline(pIntent, smallIcon, ticker, title, content, true, true, false);
currentNotify = notify1;
}
- 网易新闻样式:普通类型通知(多行)
/**
* 高仿网易新闻
*/
private void notify_normal_moreLine() {
//设置想要展示的数据内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int smallIcon = R.drawable.netease_bigicon;
String ticker = "您有一条新通知";
String title = "朱立伦请辞国民党主席 副主席黄敏惠暂代党主席";
String content = "据台湾“中央社”报道,国民党主席朱立伦今天(18日)向中常会报告,为败选请辞党主席一职,他感谢各位中常委的指教包容,也宣布未来党务工作由副主席黄敏惠暂代,完成未来所有补选工作。";
//实例化工具类,并且调用接口
NotifyUtil notify2 = new NotifyUtil(mContext, 2);
notify2.notify_normail_moreline(pIntent, smallIcon, ticker, title, content, true, true, false);
currentNotify = notify2;
}
- 微信消息样式: 消息列表通知(含双图标)
/**
* 收件箱样式
*/
private void notify_mailbox() {
//设置想要展示的数据内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int largeIcon = R.drawable.fbb_largeicon;
int smallIcon = R.drawable.wx_smallicon;
String ticker = "您有一条新通知";
String title = "冰冰";
ArrayList<String> messageList = new ArrayList<String>();
messageList.add("文明,今晚有空吗?");
messageList.add("晚上跟我一起去玩吧?");
messageList.add("怎么不回复我??我生气了!!");
messageList.add("我真生气了!!!!!你听见了吗!");
messageList.add("文明,别不理我!!!");
String content = "[" + messageList.size() + "条]" + title + ": " + messageList.get(0);
//实例化工具类,并且调用接口
NotifyUtil notify3 = new NotifyUtil(mContext, 3);
notify3.notify_mailbox(pIntent, smallIcon, largeIcon, messageList, ticker,
title, content, true, true, false);
currentNotify = notify3;
}
- 系统截图通知样式: 含大图类型通知
/**
* 高仿系统截图通知
*/
private void notify_bigPic() {
//设置想要展示的数据内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int smallIcon = R.drawable.xc_smaillicon;
int largePic = R.drawable.screenshot;
String ticker = "您有一条新通知";
String title = "已经抓取屏幕截图";
String content = "触摸可查看您的屏幕截图";
//实例化工具类,并且调用接口
NotifyUtil notify4 = new NotifyUtil(mContext, 4);
notify4.notify_bigPic(pIntent, smallIcon, ticker, title, content, largePic, true, true, false);
currentNotify = notify4;
}
- 应用宝样式: 自定义视图通知
/**
* 高仿应用宝
*/
private void notify_customview() {
//设置想要展示的数据内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
String ticker = "您有一条新通知";
//设置自定义布局中按钮的跳转界面
Intent btnIntent = new Intent(mContext, OtherActivity.class);
btnIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//如果是启动activity,那么就用PendingIntent.getActivity,如果是启动服务,那么是getService
PendingIntent Pintent = PendingIntent.getActivity(mContext,
(int) SystemClock.uptimeMillis(), btnIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// 自定义布局
RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(),
R.layout.yyb_notification);
remoteViews.setImageViewResource(R.id.image, R.drawable.yybao_bigicon);
remoteViews.setTextViewText(R.id.title, "垃圾安装包太多");
remoteViews.setTextViewText(R.id.text, "3个无用安装包,清理释放的空间");
remoteViews.setOnClickPendingIntent(R.id.button, Pintent);//定义按钮点击后的动作
int smallIcon = R.drawable.yybao_smaillicon;
//实例化工具类,并且调用接口
NotifyUtil notify5 = new NotifyUtil(mContext, 5);
notify5.notify_customview(remoteViews, pIntent, smallIcon, ticker, true, true, false);
currentNotify = notify5;
}
- Android系统更新样式: 折叠式双按钮通知
/**
* 高仿Android更新提醒样式
*/
private void notify_buttom() {
//设置想要展示的数据内容
String ticker = "您有一条新通知";
int smallIcon = R.drawable.android_bigicon;
int lefticon = R.drawable.android_leftbutton;
String lefttext = "以后再说";
Intent leftIntent = new Intent();
leftIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent leftPendIntent = PendingIntent.getActivity(mContext,
requestCode, leftIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int righticon = R.drawable.android_rightbutton;
String righttext = "安装";
Intent rightIntent = new Intent(mContext, OtherActivity.class);
rightIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent rightPendIntent = PendingIntent.getActivity(mContext,
requestCode, rightIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//实例化工具类,并且调用接口
NotifyUtil notify6 = new NotifyUtil(mContext, 6);
notify6.notify_button(smallIcon, lefticon, lefttext, leftPendIntent, righticon, righttext, rightPendIntent, ticker, "系统更新已下载完毕", "Android 6.0.1", true, true, false);
currentNotify = notify6;
}
- Android系统下载样式: 进度条通知
/**
* 高仿Android系统下载样式
*/
private void notify_progress() {
//设置想要展示的数据内容
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent rightPendIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int smallIcon = R.drawable.android_bigicon;
String ticker = "您有一条新通知";
//实例化工具类,并且调用接口
NotifyUtil notify7 = new NotifyUtil(mContext, 7);
notify7.notify_progress(rightPendIntent, smallIcon, ticker, "Android 6.0.1 下载", "正在下载中", true, false, false);
currentNotify = notify7;
}
- Heads-up 样式: Android 5.0 新特性
/**
* Android 5。0 新特性:悬浮式通知
*/
private void notify_headUp() {
//设置想要展示的数据内容
int smallIcon = R.drawable.hl_smallicon;
int largeIcon = R.drawable.fbb_largeicon;
String ticker = "您有一条新通知";
String title = "范冰冰";
String content = "文明,今晚在希尔顿酒店2016号房哈";
Intent intent = new Intent(mContext, OtherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext,
requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int lefticon = R.drawable.hl_message;
String lefttext = "回复";
Intent leftIntent = new Intent();
leftIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent leftPendingIntent = PendingIntent.getActivity(mContext,
requestCode, leftIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int righticon = R.drawable.hl_call;
String righttext = "拨打";
Intent rightIntent = new Intent(mContext, OtherActivity.class);
rightIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent rightPendingIntent = PendingIntent.getActivity(mContext,
requestCode, rightIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//实例化工具类,并且调用接口
NotifyUtil notify8 = new NotifyUtil(mContext, 8);
notify8.notify_HeadUp(pendingIntent, smallIcon, largeIcon, ticker, title, content, lefticon, lefttext, leftPendingIntent, righticon, righttext, rightPendingIntent, true, true, false);
currentNotify = notify8;
}
- 清空通知
private NotifyUtil currentNotify
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currentNotify != null) {
currentNotify.clear();
}
}
});
- 版本
- 最新 Android SDK
- Gradle
- 环境变量
- ANDROID_HOME
- GRADLE_HOME,同时把bin放入path变量
- Android SDK 安装,都更新到最新
- Android SDK Build-tools更新到最新
- Google Repository更新到最新
- Android Support Repository更新到最新
- Android Support Library更新到最新