有些手机不支持大型通知。那么我怎么能在运行时知道我的notif大或通常的大小?我还需要它支持控制按钮。 这是我的大通知代码:
{{1}}
答案 0 :(得分:0)
试试这段代码:
public static void showNotification(Context context) {
int notificationId = 99;
Intent cancelIntent = new Intent(YOUR_ACTION).putExtra(YOUR_EXTRA_NOTIFICATION_ID, notificationId);
PendingIntent buttonPendingIntent = PendingIntent.getBroadcast(context, 123, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(context)
.setAutoCancel(false)
.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setSmallIcon(android.R.drawable.stat_notify_sync)
.setTicker("Ticker title")
.setOnlyAlertOnce(true)
.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, YourActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
Notification not = notBuilder
.setContentTitle("Title")
.setContentText("Message")
.setProgress(100, 33, false)
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", buttonPendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText("Message"))
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, not);
}
它显示一个带有一个按钮的重要通知 - 您可以通过拉下底边来放大它。