高仿淘寶等熱門App的通知視圖:NotifyUtil
高仿淘寶,網易新聞,微信,應用寶,環聊等等熱門App的通知視圖,并且完通知工具類的封裝,提供多達8種最常見的App通知接口,支持Android 5.0懸浮式通知樣式。 使用說明:<
1.. 填充想要展示的內容
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);
工具類中的八種通知方法的使用展示
1. 淘寶樣式:普通類型通知(單行)
/* 高仿淘寶 */ 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; }</pre>
2. 網易新聞樣式:普通類型通知(多行)
/** * 高仿網易新聞 */ 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; }3. 微信消息樣式: 消息列表通知(含雙圖標)
/** * 收件箱樣式 */ 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; }4. 系統截圖通知樣式: 含大圖類型通知
/** * 高仿系統截圖通知 */ 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; }5. 應用寶樣式: 自定義視圖通知
/* 高仿應用寶 */ 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; }</pre>
6. 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; }</pre>
7. 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; }8. 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; }</pre>
9. 清空通知
private NotifyUtil currentNotifybutton1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentNotify != null) { currentNotify.clear(); } } });</pre>
Gradle 構建
版本
最新 Android SDK
Gradle
環境變量
ANDROID_HOME
GRADLE_HOME,同時把bin放入path變量
Android SDK 安裝,都更新到最新
Android SDK Build-tools更新到最新
Google Repository更新到最新
Android Support Repository更新到最新
Android Support Library更新到最新
</div>