本文整理匯總了Java中android.service.notification.StatusBarNotification類的典型用法代碼示例。如果您正苦於以下問題:Java StatusBarNotification類的具體用法?Java StatusBarNotification怎麽用?Java StatusBarNotification使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StatusBarNotification類屬於android.service.notification包,在下文中一共展示了StatusBarNotification類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onNotificationPosted
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
String pack = sbn.getPackageName();
String ticker = sbn.getNotification().tickerText.toString();
Bundle extras = sbn.getNotification().extras;
String title = extras.getString("android.title");
String text = extras.getCharSequence("android.text").toString();
Log.i("Package",pack);
Log.i("Ticker",ticker);
Log.i("Title",title);
Log.i("Text",text);
Intent msgrcv = new Intent("Msg");
msgrcv.putExtra("package", pack);
msgrcv.putExtra("ticker", ticker);
msgrcv.putExtra("title", title);
msgrcv.putExtra("text", text);
LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);
}
示例2: shouldBeFilteredOut
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
private boolean shouldBeFilteredOut(StatusBarNotification sbn) {
Notification notification = sbn.getNotification();
if (AndroidVersion.isAtLeastOreo()) {
getCurrentRanking().getRanking(sbn.getKey(), mTempRanking);
if (!mTempRanking.canShowBadge()) {
return true;
}
if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
// Special filtering for the default, legacy "Miscellaneous" channel.
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
return true;
}
}
}
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
return true;
}
boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text);
return (isGroupHeader || missingTitleAndText);
}
示例3: onNotificationPosted
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
if (AndroidUtils.isVersionKitKat()) {
String pack = sbn.getPackageName();
String ticker = getString(sbn.getNotification().tickerText);
Bundle extras = sbn.getNotification().extras;
String title = "";
String text = "";
if (extras != null) {
title = extras.getString("android.title");
text = getString(extras.getCharSequence("android.text")).toString();
}
Log.i("Package", pack);
Log.i("Ticker", ticker);
Log.i("Title", title);
Log.i("Text", text);
Intent msgrcv = new Intent("Msg");
msgrcv.putExtra("package", pack);
msgrcv.putExtra("ticker", ticker);
msgrcv.putExtra("title", title);
msgrcv.putExtra("text", text);
LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);
}
}
示例4: filter
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
private boolean filter(StatusBarNotification sbn) {
Notification notification = sbn.getNotification();
Log.d("blacklist", " " + blacklistedApp);
return
notification != null
// Filter low priority notifications
&& notification.priority >= minNotificationPriority
// Notification flags
&& !isOngoing(notification)
&& !isLocalOnly(notification)
&& !isBlacklisted(sbn);
}
示例5: cancelActiveNotifications
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
private static void cancelActiveNotifications(@NonNull Context context) {
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
notifications.cancel(SUMMARY_NOTIFICATION_ID);
if (Build.VERSION.SDK_INT >= 23) {
try {
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
for (StatusBarNotification activeNotification : activeNotifications) {
if (activeNotification.getId() != CallNotificationBuilder.WEBRTC_NOTIFICATION) {
notifications.cancel(activeNotification.getId());
}
}
} catch (Throwable e) {
// XXX Appears to be a ROM bug, see #6043
Log.w(TAG, e);
notifications.cancelAll();
}
}
}
示例6: onRequestRemoveSMS
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@TargetApi(21)
void onRequestRemoveSMS(String packageName, String from, String address, String displayAddress, String body, long timestamp) {
try {
for (StatusBarNotification sbn : getActiveNotifications()) {
android.app.Notification n = sbn.getNotification();
if (sbn.getPackageName().equals(packageName)) {
if (isSMSFuzzyMatch(from, address, displayAddress, body, timestamp, notificationFromStatusBarNotification(sbn))) {
if (VERSION.SDK_INT < 21) {
cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
} else {
cancelNotification(sbn.getKey());
}
}
}
}
} catch (Exception e) {
}
}
示例7: onNotificationPosted
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
if (Log.isPrint) {
Log.i(TAG, sbn.toString());
Notification notification = sbn.getNotification();
Log.i(TAG, "tickerText : " + notification.tickerText);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Bundle bundle = notification.extras;
for (String key : bundle.keySet()) {
Log.i(TAG, key + ": " + bundle.get(key));
}
}
}
if (self != null && notificationListener != null) {
notificationListener.onNotificationPosted(sbn);
}
}
示例8: clear
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
void clear(Chat chat, NotificationBuilder nb) {
int id = (int) chat.getUniqueId();
nb.getNotificationManager().cancel(id);
boolean clearGroup = true;
for (StatusBarNotification sbn : nb.getNotificationManager().getActiveNotifications()) {
if (sbn.getId() != NOTIFICATION_ID_SYSTEM
&& sbn.getId() != NOTIFICATION_ID_GROUP_SUMMARY) {
clearGroup = false;
}
}
if (clearGroup) {
nb.getNotificationManager().cancel(NOTIFICATION_ID_GROUP_SUMMARY);
}
}
示例9: updateBadgeIcon
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
/**
* Determines whether the badge should show a notification icon rather than a number,
* and sets that icon on the BadgeInfo if so.
* @param badgeInfo The badge to update with an icon (null if it shouldn't show one).
* @return Whether the badge icon potentially changed (true unless it stayed null).
*/
private boolean updateBadgeIcon(BadgeInfo badgeInfo) {
boolean hadNotificationToShow = badgeInfo.hasNotificationToShow();
NotificationInfo notificationInfo = null;
NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
if (notificationListener != null && badgeInfo.getNotificationKeys().size() >= 1) {
// Look for the most recent notification that has an icon that should be shown in badge.
for (NotificationKeyData notificationKeyData : badgeInfo.getNotificationKeys()) {
String notificationKey = notificationKeyData.notificationKey;
StatusBarNotification[] activeNotifications = notificationListener
.getActiveNotifications(new String[]{notificationKey});
if (activeNotifications.length == 1) {
notificationInfo = new NotificationInfo(mLauncher, activeNotifications[0]);
if (notificationInfo.shouldShowIconInBadge()) {
// Found an appropriate icon.
break;
} else {
// Keep looking.
notificationInfo = null;
}
}
}
}
badgeInfo.setNotificationToShow(notificationInfo);
return hadNotificationToShow || badgeInfo.hasNotificationToShow();
}
示例10: handleMessage
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
public boolean handleMessage(Message message) {
switch (message.what) {
case MSG_NOTIFICATION_POSTED:
mUiHandler.obtainMessage(message.what, message.obj).sendToTarget();
break;
case MSG_NOTIFICATION_REMOVED:
mUiHandler.obtainMessage(message.what, message.obj).sendToTarget();
break;
case MSG_NOTIFICATION_FULL_REFRESH:
final List<StatusBarNotification> activeNotifications = sIsConnected
? filterNotifications(getActiveNotifications())
: new ArrayList<StatusBarNotification>();
mUiHandler.obtainMessage(message.what, activeNotifications).sendToTarget();
break;
}
return true;
}
示例11: onNotificationRemoved
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
// super.onNotificationRemoved(sbn);
// try {
// String packageName = sbn.getPackageName();
//
// if ("com.android.incallui".equals(packageName) || "com.android.dialer".equals(packageName) || "com.google.android.dialer".equals(packageName)) {
//
// Bundle extras = sbn.getNotification().extras;
//
// if ("Ongoing call".equals(extras.getString(Notification.EXTRA_TEXT)) || "Текущий вызов".equals(extras.getString(Notification.EXTRA_TEXT))) {
//
//// Toast.makeText(getApplicationContext(), "Ongoing call", Toast.LENGTH_LONG).show();
//
// } else if (isCallIn && ("Incoming call".equals(extras.getString(Notification.EXTRA_TEXT)) || "Входящий вызов".equals(extras.getString(Notification.EXTRA_TEXT)))) {
// onCallInEnded();
//// CustomNotification notification = new CustomNotification(context, name, number);
//// notification.cancel();
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
}
示例12: findExistItem
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
private NotificationBarInfoItem findExistItem(StatusBarNotification statusBarNotification) {
if (statusBarNotification == null || statusBarNotification.getPackageName() == null) {
return null;
}
if (CollectionUtils.isEmpty(notificationInfo.getData())) {
return null;
}
CharSequence packageName = statusBarNotification.getPackageName();
int id = statusBarNotification.getId();
for (NotificationBarInfoItem notificationBarInfoItem : notificationInfo.getData()) {
if (id == notificationBarInfoItem.getNotifyId() && TextUtils.equals(packageName, notificationBarInfoItem.getPackageName()) && notificationBarInfoItem.getType() == 1) {
return notificationBarInfoItem;
}
}
return null;
}
示例13: getForegroundServiceList
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
public List<String> getForegroundServiceList() {
List<String> list = new ArrayList<>();
if (mNotificationService != null) {
StatusBarNotification[] notifications = mNotificationService.getActiveNotifications();
for (StatusBarNotification notification : notifications) {
int mask = Notification.FLAG_FOREGROUND_SERVICE;
if ((notification.getNotification().flags & mask) != 0) {
list.add(notification.getPackageName());
}
}
}
return list;
}
示例14: parse
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
public void parse(ProcessedNotification target, StatusBarNotification source)
{
Notification notification = source.getNotification();
if (!tryParseNatively(notification))
{
parseFromNotificationView(notification);
}
if (title == null || title.trim().isEmpty()) {
PackageManager packageManager = context.getPackageManager();
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(source.getPackageName(), 0);
title = packageManager.getApplicationLabel(applicationInfo).toString();
} catch (PackageManager.NameNotFoundException ignored) {
}
}
target.setText(text);
target.setTitle(title);
}
示例15: onNotificationPosted
import android.service.notification.StatusBarNotification; //導入依賴的package包/類
@Override
public void onNotificationPosted (StatusBarNotification sbn)
{
Intent intent = new Intent(String.valueOf(R.string.app_name));
intent.setClass(this, NotificationBroadcastReceiver.class);
intent.setAction(actions.NOTIFICATION_RECEIVED.toString());
try
{
PackageManager packageManager = getApplicationContext().getPackageManager();
ApplicationInfo applicationInfo;
applicationInfo = packageManager.getApplicationInfo(sbn.getPackageName(), 0);
intent.putExtra("app name", packageManager.getApplicationLabel(applicationInfo));
}
catch(PackageManager.NameNotFoundException e)
{
intent.putExtra("app name", "unknown application");
}
intent.putExtra("title", sbn.getNotification().extras.getString("android.title"));
intent.putExtra("data", sbn.getNotification().extras.getString("android.text"));
sendBroadcast(intent);
}