Java Code Examples for android.app.Notification#InboxStyle
The following examples show how to use
android.app.Notification#InboxStyle .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From AndroidDemo with MIT License | 5 votes |
public void inBoxStyle(){ // 获取系统 通知管理 服务 NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this);// 构建 Notification builder.setContentTitle("这里是通知的标题~") .setSmallIcon(R.drawable.ic_play) .setContentText("这里是通知的内容!"); Notification.InboxStyle inboxStyle = new Notification.InboxStyle(); inboxStyle.addLine("First line.");// 添加行 inboxStyle.addLine("Second line"); inboxStyle.addLine("Third line"); inboxStyle.addLine("Last line"); inboxStyle.setBigContentTitle("ContentTitle");// 设置标题以及简介文字 inboxStyle.setSummaryText("SummaryText"); builder.setStyle(inboxStyle); // 兼容 API 26,Android 8.0 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ // 第三个参数表示通知的重要程度,默认则只在通知栏闪烁一下 NotificationChannel notificationChannel = new NotificationChannel("AppTestNotificationId", "AppTestNotificationName", NotificationManager.IMPORTANCE_DEFAULT); // 注册通道,注册后除非卸载再安装否则不改变 notificationManager.createNotificationChannel(notificationChannel); builder.setChannelId("AppTestNotificationId"); } // 发出通知 notificationManager.notify(1, builder.build()); }
Example 2
Source File: NotificationCompatJellybean.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void addInboxStyle(CharSequence bigContentTitle, boolean useSummary, CharSequence summaryText, ArrayList<CharSequence> texts) { Notification.InboxStyle style = new Notification.InboxStyle(b) .setBigContentTitle(bigContentTitle); if (useSummary) { style.setSummaryText(summaryText); } for (CharSequence text: texts) { style.addLine(text); } }
Example 3
Source File: NotificationCompatJellybean.java From adt-leanback-support with Apache License 2.0 | 5 votes |
public static void addInboxStyle(NotificationBuilderWithBuilderAccessor b, CharSequence bigContentTitle, boolean useSummary, CharSequence summaryText, ArrayList<CharSequence> texts) { Notification.InboxStyle style = new Notification.InboxStyle(b.getBuilder()) .setBigContentTitle(bigContentTitle); if (useSummary) { style.setSummaryText(summaryText); } for (CharSequence text: texts) { style.addLine(text); } }
Example 4
Source File: NotificationCompatJellybean.java From V.FlyoutTest with MIT License | 5 votes |
public void addInboxStyle(CharSequence bigContentTitle, boolean useSummary, CharSequence summaryText, ArrayList<CharSequence> texts) { Notification.InboxStyle style = new Notification.InboxStyle(b) .setBigContentTitle(bigContentTitle); if (useSummary) { style.setSummaryText(summaryText); } for (CharSequence text: texts) { style.addLine(text); } }
Example 5
Source File: UpgradeService.java From catnut with MIT License | 5 votes |
private void checkout() throws Exception { URL url = new URL(METADATA_URL); InputStream inputStream = url.openStream(); Scanner in = new Scanner(inputStream).useDelimiter("\\A"); if (in.hasNext()) { JSONObject metadata = new JSONObject(in.next()); PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); if (info.versionCode < metadata.optInt(FIELD_VERSION_CODE)) { Notification.InboxStyle style = new Notification.InboxStyle(mBuilder); String size = metadata.optString("size"); style.setBigContentTitle(getString(R.string.find_new_version, size)); JSONArray messages = metadata.optJSONArray("messages"); for (int i = 0; i < messages.length(); i++) { style.addLine(messages.optString(i)); } // download&upgrade intent Intent download = new Intent(this, UpgradeService.class); download.setAction(ACTION_DOWNLOAD); download.putExtra(DOWNLOAD_LINK, metadata.optString(DOWNLOAD_LINK)); PendingIntent piDownload = PendingIntent.getService(this, 0, download, 0); mBuilder.addAction(R.drawable.ic_stat_download_dark, getString(R.string.down_load_and_upgrade), piDownload); // dismiss notification Intent dismiss = new Intent(this, UpgradeService.class); dismiss.setAction(ACTION_DISMISS); PendingIntent piDismiss = PendingIntent.getService(this, 0, dismiss, 0); mBuilder.addAction(R.drawable.ic_stat_content_remove_dark, getString(R.string.not_upgrade_now), piDismiss); // show it. mBuilder.setTicker(getString(R.string.find_new_version)); mNotificationManager.notify(ID, mBuilder.setDefaults(Notification.DEFAULT_ALL).build()); } else { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(UpgradeService.this, getString(R.string.already_updated), Toast.LENGTH_SHORT).show(); } }); } } in.close(); }
Example 6
Source File: NotificationCompatJellybean.java From guideshow with MIT License | 5 votes |
public void addInboxStyle(CharSequence bigContentTitle, boolean useSummary, CharSequence summaryText, ArrayList<CharSequence> texts) { Notification.InboxStyle style = new Notification.InboxStyle(b) .setBigContentTitle(bigContentTitle); if (useSummary) { style.setSummaryText(summaryText); } for (CharSequence text: texts) { style.addLine(text); } }
Example 7
Source File: DataTrackerService.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
private synchronized void initiateUpdate() { mBuilder.setContentTitle("Data traffic"); // String.format("↓%s@%s%s, ↑%s@%s%s, ⇅%s@%s%s", // Formatter.formatFileSize(getApplicationContext(), totalRxSincePrev), // Util.nf.format(rateTotalRxSincePrev), // unitTypeArr[unitType], // Formatter.formatFileSize(getApplicationContext(), totalTxSincePrev), // Util.nf.format(rateTotalTxSincePrev), // unitTypeArr[unitType], // Formatter.formatFileSize(getApplicationContext(), (totalRxSincePrev + totalTxSincePrev)), // Util.nf.format(rateTotalRxSincePrev + rateTotalTxSincePrev), // unitTypeArr[unitType])); if (rateTotalTxSincePrev == 0 && rateTotalRxSincePrev == 0) { mBuilder.setSmallIcon(android.R.drawable.ic_menu_more); } else if (rateTotalTxSincePrev == 0 && rateTotalRxSincePrev > 0) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_download); } else if (rateTotalTxSincePrev > 0 && rateTotalRxSincePrev == 0) { mBuilder.setSmallIcon(android.R.drawable.stat_sys_upload); } else if (rateTotalTxSincePrev > 0 && rateTotalRxSincePrev > 0) {//1307 bytes is equal to .1Mbit mBuilder.setSmallIcon(android.R.drawable.ic_notification_overlay); } final Notification.InboxStyle big = new Notification.InboxStyle(); big.addLine(String.format("↓%s@%s%s", Formatter.formatFileSize(getApplicationContext(), totalRxSincePrev), Util.nf.format(rateTotalRxSincePrev), unitTypeArr[unitType])); big.addLine(String.format("↑%s@%s%s", Formatter.formatFileSize(getApplicationContext(), totalTxSincePrev), Util.nf.format(rateTotalTxSincePrev), unitTypeArr[unitType])); big.addLine(String.format("⇅%s@%s%s", Formatter.formatFileSize(getApplicationContext(), (totalRxSincePrev + totalTxSincePrev)), Util.nf.format(rateTotalRxSincePrev + rateTotalTxSincePrev), unitTypeArr[unitType])); // long rateRxSincePrev; // long rateTxSincePrev; // final Context applicationContext = getApplicationContext(); // final int gap = pollRate * 1000 / appStatsList.size(); // for (AppStats appStat : appStatsList) { // rateRxSincePrev = appStat.bytesRxSincePrev * 1000000 / (appStat.elapsedTimeSincePrev / 1000); // rateTxSincePrev = appStat.bytesTxSincePrev * 1000000 / (appStat.elapsedTimeSincePrev / 1000); // if (unitType > 3) { // rateRxSincePrev = (rateRxSincePrev >> (10 * (unitType - 4))); // rateTxSincePrev = (rateTxSincePrev >> (10 * (unitType - 4))); // } else { // rateRxSincePrev = ((rateRxSincePrev >> (10 * unitType)) << 3); // rateTxSincePrev = ((rateTxSincePrev >> (10 * unitType)) << 3); // } // big.addLine(String.format("%s\n↓%s@%s%s, ↑%s@%s%s, ⇅%s@%s%s", // appStat.name, // Formatter.formatFileSize(applicationContext, appStat.bytesRxSincePrev), // Util.nf.format(rateRxSincePrev), // unitTypeArr[unitType], // Formatter.formatFileSize(applicationContext, appStat.bytesTxSincePrev), // Util.nf.format(rateTxSincePrev), // unitTypeArr[unitType], // Formatter.formatFileSize(applicationContext, (appStat.bytesRxSincePrev + appStat.bytesTxSincePrev)), // Util.nf.format(rateRxSincePrev + rateTxSincePrev), // unitTypeArr[unitType])); // try { // Thread.sleep(gap); // } catch (InterruptedException e) {} // } mNotifyMgr.notify(mNotificationId, mBuilder.setStyle(big).build()); }
Example 8
Source File: MainActivity.java From movim_android with GNU Affero General Public License v3.0 | 4 votes |
@JavascriptInterface public void showNotification(String title, String body, String picture, String action) { Bitmap pictureBitmap = getBitmapFromURL(picture); Intent i = new Intent(this, MainActivity.class); if (action != null) { i.setAction(action); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); } PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // The deleteIntent declaration Intent deleteIntent = new Intent(action); PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); registerReceiver(receiver, new IntentFilter(action)); // Integer counter; List<String> messages = null; // There is already pending notifications if (this.notifs.get(action) != null) { messages = this.notifs.get(action); } else { messages = new ArrayList<String>(); } messages.add(body); if (messages.size() > 5) { messages.remove(0); } this.notifs.put(action, messages); // We create the inbox Notification.InboxStyle style = new Notification.InboxStyle(); for (int j = 0; j < messages.size(); j++) { style.addLine(messages.get(j)); } style.setBigContentTitle(title); Notification notification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_stat_name) .setLargeIcon(pictureBitmap).setContentTitle(title).setContentText(body).setContentIntent(pi) .setDeleteIntent(pendingDeleteIntent).setAutoCancel(true).setColor(Color.parseColor("#3F51B5")) .setLights(Color.parseColor("#3F51B5"), 1000, 5000).setNumber(messages.size()).setStyle(style) .setGroup("movim").build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(action, 0, notification); }
Example 9
Source File: PloggyService.java From ploggy with GNU General Public License v3.0 | 4 votes |
private void updateNotification(List<Data.AnnotatedMessage> newMessages) { // Max, as per documentation: http://developer.android.com/reference/android/app/Notification.InboxStyle.html final int MAX_LINES = 5; // Invoke main Activity when notification is clicked Intent intent = new Intent(this, ActivityMain.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); int iconResourceId; String contentTitle; if (newMessages != null && newMessages.size() > 0) { intent.setAction(ActivityMain.ACTION_DISPLAY_MESSAGES); iconResourceId = R.drawable.ic_notification_with_new_messages; contentTitle = getResources().getQuantityString( R.plurals.foreground_service_notification_content_title_with_new_messages, newMessages.size(), newMessages.size()); } else { intent.setAction("android.intent.action.MAIN"); iconResourceId = R.drawable.ic_notification_without_new_messages; contentTitle = getString(R.string.foreground_service_notification_content_title_without_new_messages); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder notificationBuilder = new Notification.Builder(this) .setContentIntent(pendingIntent) .setContentTitle(contentTitle) .setSmallIcon(iconResourceId); Notification notification; if (newMessages != null && newMessages.size() > 0) { // Use default (system) sound, lights, and vibrate notificationBuilder.setDefaults(Notification.DEFAULT_ALL); // Build email-style big view with summary of new messages Notification.InboxStyle inboxStyleBuilder = new Notification.InboxStyle(notificationBuilder); for (int i = 0; i < MAX_LINES && i < newMessages.size(); i++) { inboxStyleBuilder.addLine( Html.fromHtml( getString( R.string.foreground_service_notification_inbox_line, newMessages.get(i).mPublicIdentity.mNickname, newMessages.get(i).mMessage.mContent))); } if (newMessages.size() > MAX_LINES) { inboxStyleBuilder.setSummaryText( getString( R.string.foreground_service_notification_inbox_summary, newMessages.size() - MAX_LINES)); } notification = inboxStyleBuilder.build(); } else { notification = notificationBuilder.build(); } if (mNotification == null) { mNotification = notification; } else { // TODO: if other notification attributes are added (ie ticker), copy them here mNotification.contentIntent = notification.contentIntent; mNotification.bigContentView = notification.bigContentView; mNotification.contentView = notification.contentView; mNotification.icon = notification.icon; mNotification.largeIcon = notification.largeIcon; mNotification.defaults = notification.defaults; } }