本文整理匯總了Java中android.support.v4.app.NotificationCompat.Builder.setDefaults方法的典型用法代碼示例。如果您正苦於以下問題:Java Builder.setDefaults方法的具體用法?Java Builder.setDefaults怎麽用?Java Builder.setDefaults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.app.NotificationCompat.Builder
的用法示例。
在下文中一共展示了Builder.setDefaults方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: displayOpenFileNotification
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private void displayOpenFileNotification() {
Intent notificationIntent = getOpenIntent();
int icon = R.mipmap.video2;
CharSequence title = getResources().getText(R.string.open_file);
long when = System.currentTimeMillis();
PendingIntent contentIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, 0);
Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setSmallIcon(icon);
notificationBuilder.setTicker(null);
notificationBuilder.setOnlyAlertOnce(true);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(mProcessedFiles.get(0).getName());
notificationBuilder.setContentIntent(contentIntent);
notificationBuilder.setWhen(when);
notificationBuilder.setDefaults(0); // no sound, no light, no vibrate
mNotificationManager.notify(OPEN_NOTIFICATION_ID, notificationBuilder.build());
}
示例2: modifyForSoundVibrationAndLight
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, SharedPreferences preferences) {
final Resources resources = mXmppConnectionService.getResources();
final String ringtone = preferences.getString("notification_ringtone", resources.getString(R.string.notification_ringtone));
final boolean vibrate = preferences.getBoolean("vibrate_on_notification", resources.getBoolean(R.bool.vibrate_on_notification));
final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led));
final boolean headsup = preferences.getBoolean("notification_headsup", resources.getBoolean(R.bool.headsup_notifications));
if (notify && !isQuietHours()) {
if (vibrate) {
final int dat = 70;
final long[] pattern = {0, 3 * dat, dat, dat};
mBuilder.setVibrate(pattern);
} else {
mBuilder.setVibrate(new long[]{0});
}
Uri uri = Uri.parse(ringtone);
try {
mBuilder.setSound(fixRingtoneUri(uri));
} catch (SecurityException e) {
Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString());
}
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setCategory(Notification.CATEGORY_MESSAGE);
}
mBuilder.setPriority(notify ? (headsup ? NotificationCompat.PRIORITY_HIGH : NotificationCompat.PRIORITY_DEFAULT) : NotificationCompat.PRIORITY_LOW);
setNotificationColor(mBuilder);
mBuilder.setDefaults(0);
if (led) {
mBuilder.setLights(0xff0080FF, 2000, 3000);
}
}
示例3: modifyForSoundVibrationAndLight
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, SharedPreferences preferences) {
final Resources resources = mXmppConnectionService.getResources();
final String ringtone = preferences.getString("notification_ringtone", resources.getString(R.string.notification_ringtone));
final boolean vibrate = preferences.getBoolean("vibrate_on_notification", resources.getBoolean(R.bool.vibrate_on_notification));
final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led));
final boolean headsup = preferences.getBoolean("notification_headsup", resources.getBoolean(R.bool.headsup_notifications));
if (notify && !isQuietHours()) {
if (vibrate) {
final int dat = 70;
final long[] pattern = {0, 3 * dat, dat, dat};
mBuilder.setVibrate(pattern);
} else {
mBuilder.setVibrate(new long[]{0});
}
Uri uri = Uri.parse(ringtone);
try {
mBuilder.setSound(fixRingtoneUri(uri));
} catch (SecurityException e) {
Log.d(Config.LOGTAG,"unable to use custom notification sound "+uri.toString());
}
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setCategory(Notification.CATEGORY_MESSAGE);
}
mBuilder.setPriority(notify ? (headsup ? NotificationCompat.PRIORITY_HIGH : NotificationCompat.PRIORITY_DEFAULT) : NotificationCompat.PRIORITY_LOW);
setNotificationColor(mBuilder);
mBuilder.setDefaults(0);
if (led) {
mBuilder.setLights(0xff00FF00, 2000, 3000);
}
}
示例4: getBuilder
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
public static Builder getBuilder(Context context, boolean alert)
{
Builder builder = new Builder(context).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true);
if (alert == true)
{
int defaults = 0;
if (KlyphPreferences.getNotificationRingtone() != null && KlyphPreferences.getNotificationRingtone().equals("default"))
{
defaults |= android.app.Notification.DEFAULT_SOUND;
}
else if (KlyphPreferences.getNotificationRingtoneUri() == null)
{
builder.setSound(null);
}
else
{
builder.setSound(Uri.parse(KlyphPreferences.getNotificationRingtoneUri()));
}
if (KlyphPreferences.isNotificationVibrationEnabled() == true)
defaults |= android.app.Notification.DEFAULT_VIBRATE;
defaults |= android.app.Notification.DEFAULT_LIGHTS;
builder.setDefaults(defaults);
builder.setOnlyAlertOnce(true);
}
return builder;
}
示例5: getBuilder
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
public static Builder getBuilder(Context context, boolean alert)
{
Builder builder = new Builder(context).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setOnlyAlertOnce(!alert);
int defaults = 0;
if (alert == true)
{
if (MessengerPreferences.getNotificationRingtone() != null && MessengerPreferences.getNotificationRingtone().equals("default"))
{
defaults |= android.app.Notification.DEFAULT_SOUND;
}
else if (MessengerPreferences.getNotificationRingtoneUri() == null)
{
builder.setSound(null);
}
else
{
builder.setSound(Uri.parse(MessengerPreferences.getNotificationRingtoneUri()));
}
if (MessengerPreferences.isNotificationVibrationEnabled() == true)
defaults |= android.app.Notification.DEFAULT_VIBRATE;
defaults |= android.app.Notification.DEFAULT_LIGHTS;
builder.setDefaults(defaults);
}
//int defaults = android.app.Notification.DEFAULT_SOUND | android.app.Notification.DEFAULT_VIBRATE;
builder.setDefaults(defaults);
return builder;
}
示例6: applyStyle
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private static void applyStyle (final Builder nb, final NotificationStyle ns) {
int defaults = 0;
if (ns.isLights()) defaults |= Notification.DEFAULT_LIGHTS;
if (ns.isVibrate()) defaults |= Notification.DEFAULT_VIBRATE;
if (ns.isSound()) defaults |= Notification.DEFAULT_SOUND;
nb.setDefaults(defaults);
}
示例7: showInNotificationBar
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
private void showInNotificationBar(String title,String ticker, Bitmap iconBitmap,int notificationId,Intent intent) {
logger.d("notification#showInNotificationBar title:%s ticker:%s",title,ticker);
NotificationManager notifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
if (notifyMgr == null) {
return;
}
Builder builder = new NotificationCompat.Builder(ctx);
builder.setContentTitle(title);
builder.setContentText(ticker);
builder.setSmallIcon(R.drawable.tt_small_icon);
builder.setTicker(ticker);
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(true);
// this is the content near the right bottom side
// builder.setContentInfo("content info");
if (configurationSp.getCfg(SysConstant.SETTING_GLOBAL,ConfigurationSp.CfgDimension.VIBRATION)) {
// delay 0ms, vibrate 200ms, delay 250ms, vibrate 200ms
long[] vibrate = {0, 200, 250, 200};
builder.setVibrate(vibrate);
} else {
logger.d("notification#setting is not using vibration");
}
// sound
if (configurationSp.getCfg(SysConstant.SETTING_GLOBAL,ConfigurationSp.CfgDimension.SOUND)) {
builder.setDefaults(Notification.DEFAULT_SOUND);
} else {
logger.d("notification#setting is not using sound");
}
if (iconBitmap != null) {
logger.d("notification#fetch icon from network ok");
builder.setLargeIcon(iconBitmap);
} else {
// do nothint ?
}
// if MessageActivity is in the background, the system would bring it to
// the front
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
Notification notification = builder.build();
notifyMgr.notify(notificationId, notification);
}
示例8: updateNotification
import android.support.v4.app.NotificationCompat.Builder; //導入方法依賴的package包/類
public void updateNotification(final boolean notify) {
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService
.getSystemService(Context.NOTIFICATION_SERVICE);
final SharedPreferences preferences = mXmppConnectionService.getPreferences();
final String ringtone = preferences.getString("notification_ringtone", null);
final boolean vibrate = preferences.getBoolean("vibrate_on_notification", true);
if (notifications.size() == 0) {
notificationManager.cancel(NOTIFICATION_ID);
} else {
if (notify) {
this.markLastNotification();
}
final Builder mBuilder;
if (notifications.size() == 1) {
mBuilder = buildSingleConversations(notify);
} else {
mBuilder = buildMultipleConversation();
}
if (notify && !isQuietHours()) {
if (vibrate) {
final int dat = 70;
final long[] pattern = {0, 3 * dat, dat, dat};
mBuilder.setVibrate(pattern);
}
if (ringtone != null) {
mBuilder.setSound(Uri.parse(ringtone));
}
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setCategory(Notification.CATEGORY_MESSAGE);
}
setNotificationColor(mBuilder);
mBuilder.setDefaults(0);
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setDeleteIntent(createDeleteIntent());
mBuilder.setLights(0xff00FF00, 2000, 3000);
final Notification notification = mBuilder.build();
notificationManager.notify(NOTIFICATION_ID, notification);
}
}