本文整理匯總了Java中android.support.v4.app.NotificationCompat.Builder.setOngoing方法的典型用法代碼示例。如果您正苦於以下問題:Java Builder.setOngoing方法的具體用法?Java Builder.setOngoing怎麽用?Java Builder.setOngoing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.app.NotificationCompat.Builder
的用法示例。
在下文中一共展示了Builder.setOngoing方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showNotification
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private void showNotification(String animeURL) {
// Build notification
Builder notificationBuilder = new Builder(mContext);
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setContentTitle(animeURL);
notificationBuilder.setContentText("Parsing required anime data");
notificationBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
notificationBuilder.setOngoing(false);
notificationBuilder.setProgress(0, 0, true);
Intent i = new Intent(mContext, MainActivity.class);
notificationBuilder.setContentIntent(PendingIntent.getActivity(mContext, animeURL.hashCode(), i, PendingIntent.FLAG_UPDATE_CURRENT));
/**
RemoteViews contentView = new RemoteViews(mContext.getApplicationContext().getPackageName(), R.layout.download_notif_dark);
contentView.setImageViewResource(R.id.status_icon, R.mipmap.ic_launcher);
contentView.setTextViewText(R.id.status_text, "Parsing missing anime " + animeURL);
contentView.setProgressBar(R.id.status_progress, 50, 0, true);
contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE);
notificationBuilder.setContent(contentView);
Intent i = new Intent(mContext, MainActivity.class);
notificationBuilder.setContentIntent(PendingIntent.getActivity(mContext, animeURL.hashCode(), i, PendingIntent.FLAG_UPDATE_CURRENT));
final Notification notification = notificationBuilder.getNotification();
notification.contentView = contentView;
**/
if (notificationBuilder != null) {
mNotificationMap.put(animeURL.hashCode(), animeURL.hashCode());
mNotificationManager.notify(animeURL.hashCode(), notificationBuilder.build());
}
}
示例2: notifyRegisteredAccounts
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
public synchronized void notifyRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) {
if (!isServiceWrapper) {
Log.e(THIS_FILE, "Trying to create a service notification from outside the service");
return;
}
int icon = R.drawable.ic_stat_sipok;
CharSequence tickerText = context.getString(R.string.service_ticker_registered_text);
long when = System.currentTimeMillis();
Builder nb = new Builder(context);
nb.setSmallIcon(icon);
nb.setTicker(tickerText);
nb.setWhen(when);
Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RegistrationNotification contentView = new RegistrationNotification(context.getPackageName());
contentView.clearRegistrations();
if(!Compatibility.isCompatible(9)) {
contentView.setTextsColor(notificationPrimaryTextColor);
}
contentView.addAccountInfos(context, activeAccountsInfos);
// notification.setLatestEventInfo(context, contentTitle,
// contentText, contentIntent);
nb.setOngoing(true);
nb.setOnlyAlertOnce(true);
nb.setContentIntent(contentIntent);
nb.setContent(contentView);
Notification notification = nb.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
// We have to re-write content view because getNotification setLatestEventInfo implicitly
notification.contentView = contentView;
if (showNumbers) {
// This only affects android 2.3 and lower
notification.number = activeAccountsInfos.size();
}
startForegroundCompat(REGISTER_NOTIF_ID, notification);
}
示例3: setAlarm
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private void setAlarm(long interval, boolean repeat) {
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(ACTION_KEEP_ALIVE);
intent.setClass(mContext, LoginService.class);
PendingIntent pi = PendingIntent.getService(mContext, REQUEST_CODE
, intent
, PendingIntent.FLAG_CANCEL_CURRENT);
long next = System.currentTimeMillis() + interval + 1000;
if (repeat) {
am.setRepeating(AlarmManager.RTC_WAKEUP, next, REPEAT_FREQ, pi);
// if show notification is enabled, show it
if (SettingsManager.getBoolean(mContext, SettingsManager.SHOW_NOTIF
, true)) {
long now = System.currentTimeMillis();
int limit = SettingsManager.getInt(mContext
, SettingsManager.KEEP_ALIVE, -1);
long login = SettingsManager.getLong(mContext
, SettingsManager.LOG_IN_TIME, now);
NotificationManager nm = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
Builder b = new NotificationCompat.Builder(mContext);
b.setOngoing(true);
b.setContentTitle(getResources().getString(R.string.app_name));
b.setContentText(getResources().getString(R.string.from)
+ " : " + sdf.format(new Date(login))
+ (limit <= 0 ? "" : " | " + getResources().getString(R
.string.upto) + " : " + sdf.format(new Date(login
+ limit * DateUtils.HOUR_IN_MILLIS))));
b.setSmallIcon(R.drawable.ic_launcher);
b.setTicker(getResources().getString(R.string.logged_in)
+ ", " + getResources().getString(R.string.internet_access));
Intent i = new Intent(mContext, CredentialActivity.class);
PendingIntent pia = PendingIntent.getActivity(mContext, 0, i, Intent
.FLAG_ACTIVITY_CLEAR_TOP);
b.setContentIntent(pia);
Notification n = b.build();
nm.notify(1000, n);
}
} else {
am.set(AlarmManager.RTC_WAKEUP, next, pi);
}
}