android.app.Notification#DEFAULT_LIGHTS源码实例Demo

下面列出了android.app.Notification#DEFAULT_LIGHTS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: NekoSMS   文件: NotificationHelper.java
private static void applyNotificationStyle(Context context, Notification notification) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        return;
    }

    SharedPreferences prefs = context.getSharedPreferences(PreferenceConsts.FILE_MAIN, Context.MODE_PRIVATE);
    String ringtone = prefs.getString(PreferenceConsts.KEY_NOTIFICATIONS_RINGTONE, PreferenceConsts.KEY_NOTIFICATIONS_RINGTONE_DEFAULT);
    if (!TextUtils.isEmpty(ringtone)) {
        notification.sound = Uri.parse(ringtone);
    }
    if (prefs.getBoolean(PreferenceConsts.KEY_NOTIFICATIONS_VIBRATE, PreferenceConsts.KEY_NOTIFICATIONS_VIBRATE_DEFAULT)) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (prefs.getBoolean(PreferenceConsts.KEY_NOTIFICATIONS_LIGHTS, PreferenceConsts.KEY_NOTIFICATIONS_LIGHTS_DEFAULT)) {
        notification.defaults |= Notification.DEFAULT_LIGHTS;
    }
    String priority = prefs.getString(PreferenceConsts.KEY_NOTIFICATIONS_PRIORITY, PreferenceConsts.KEY_NOTIFICATIONS_PRIORITY_DEFAULT);
    notification.priority = Integer.parseInt(priority);
}
 
源代码2 项目: Linphone4Android   文件: LinphoneService.java
public void addCustomNotification(Intent onClickIntent, int iconResourceID, String title, String message, boolean isOngoingEvent) {
	PendingIntent notifContentIntent = PendingIntent.getActivity(this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
	
	Bitmap bm = null;
	try {
		bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
	} catch (Exception e) {
	}
	mCustomNotif = Compatibility.createNotification(this, title, message, iconResourceID, 0, bm, notifContentIntent, isOngoingEvent,notifcationsPriority);
	
	mCustomNotif.defaults |= Notification.DEFAULT_VIBRATE;
	mCustomNotif.defaults |= Notification.DEFAULT_SOUND;
	mCustomNotif.defaults |= Notification.DEFAULT_LIGHTS;
	
	notifyWrapper(CUSTOM_NOTIF_ID, mCustomNotif);
}
 
源代码3 项目: NotificationHelper   文件: NotifyHelper.java
public NotifyHelper identifier(int id) {
    if (id <= 0) {
        throw new IllegalStateException("Notification ID Should Not Be Less Than Or Equal To Zero!");
    }
    Integer value = flagMap.get(this.notificationId);
    if (value == null) {
        value = Notification.DEFAULT_LIGHTS;
    }
    flagMap.put(id, value);
    this.notificationId = id;
    return this;
}
 
public static Notification buildCallNotification(Context context, String roomName, String roomId, String matrixId, String callId) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setWhen(System.currentTimeMillis());

    builder.setContentTitle(roomName);
    builder.setContentText(context.getString(R.string.call_in_progress));

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        builder.setSmallIcon(R.drawable.ic_menu_small_matrix);
    } else {
        builder.setSmallIcon(R.drawable.ic_menu_small_matrix_transparent);
    }


    // Build the pending intent for when the notification is clicked
    Intent roomIntent = new Intent(context, RoomActivity.class);
    roomIntent.putExtra(RoomActivity.EXTRA_ROOM_ID, roomId);
    roomIntent.putExtra(RoomActivity.EXTRA_MATRIX_ID, matrixId);
    roomIntent.putExtra(RoomActivity.EXTRA_START_CALL_ID, callId);

    // Recreate the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context)
            .addParentStack(RoomActivity.class)
            .addNextIntent(roomIntent);


    // android 4.3 issue
    // use a generator for the private requestCode.
    // When using 0, the intent is not created/launched when the user taps on the notification.
    //
    PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000), PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    Notification n = builder.build();
    n.flags |= Notification.FLAG_SHOW_LIGHTS;
    n.defaults |= Notification.DEFAULT_LIGHTS;

    return n;
}
 
源代码5 项目: opentasks   文件: Toggled.java
@Override
public int value()
{
    if (mFlag != Notification.DEFAULT_VIBRATE && mFlag != Notification.DEFAULT_SOUND && mFlag != Notification.DEFAULT_LIGHTS)
    {
        throw new IllegalArgumentException("Notification signal flag is not valid: " + mFlag);
    }
    return mEnable ? addFlag(mOriginal.value(), mFlag) : removeFlag(mOriginal.value(), mFlag);
}
 
源代码6 项目: fanfouapp-opensource   文件: AlarmHelper.java
public final static void setNotificationType(final Context context,
        final Notification notification) {
    final AudioManager am = (AudioManager) context
            .getSystemService(Context.AUDIO_SERVICE);
    if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        final String ringFile = OptionHelper.readString(context,
                R.string.option_notification_ringtone, null);
        Uri ringTone = null;
        if (!TextUtils.isEmpty(ringFile)) {
            ringTone = Uri.parse(ringFile);
            notification.sound = ringTone;
        }
    }

    final boolean vibrate = OptionHelper.readBoolean(context,
            R.string.option_notification_vibrate, false);
    if (vibrate) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    } else {
        notification.vibrate = null;
    }

    final boolean led = OptionHelper.readBoolean(context,
            R.string.option_notification_led, false);
    if (led) {
        notification.defaults |= Notification.DEFAULT_LIGHTS;
    } else {
        notification.ledOnMS = 0;
        notification.ledOffMS = 0;
    }
}
 
源代码7 项目: FwdPortForwardingApp   文件: ForwardingService.java
/**
 * Construct a notification
 */
private void showForwardingEnabledNotification() {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_fwd_24dp)
                    .setContentTitle(getString(R.string.notification_forwarding_active_title))
                    .setContentText(getString(R.string.notification_forwarding_touch_disable_text));

    mBuilder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS;

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}
 
源代码8 项目: NotifyUtil   文件: NotifyUtil0.java
/**
     * 设置在顶部通知栏中的各种信息
     *
     * @param pendingIntent
     * @param smallIcon
     * @param ticker
     */
    private void setCompatBuilder(PendingIntent pendingIntent, int smallIcon, String ticker,
                                  String title, String content, boolean sound, boolean vibrate, boolean lights) {
//        // 如果当前Activity启动在前台,则不开启新的Activity。
//        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//        // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
//        // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
//        PendingIntent pIntent = PendingIntent.getActivity(mContext,
//                requestCode, intent, FLAG);

        cBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
        cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
        cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息

        cBuilder.setContentTitle(title);// 设置通知中心的标题
        cBuilder.setContentText(content);// 设置通知中心中的内容
        cBuilder.setWhen(System.currentTimeMillis());
        //cBuilder.setStyle()

		/*
         * 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
		 * 不设置的话点击消息后也不清除,但可以滑动删除
		 */
        cBuilder.setAutoCancel(true);
        // 将Ongoing设为true 那么notification将不能滑动删除
        // notifyBuilder.setOngoing(true);
        /*
         * 从Android4.1开始,可以通过以下方法,设置notification的优先级,
		 * 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
		 */
        cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
        /*
         * Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
		 * Notification.DEFAULT_SOUND:系统默认铃声。
		 * Notification.DEFAULT_VIBRATE:系统默认震动。
		 * Notification.DEFAULT_LIGHTS:系统默认闪光。
		 * notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
		 */
        int defaults = 0;

        if (sound) {
            defaults |= Notification.DEFAULT_SOUND;
        }
        if (vibrate) {
            defaults |= Notification.DEFAULT_VIBRATE;
        }
        if (lights) {
            defaults |= Notification.DEFAULT_LIGHTS;
        }

        cBuilder.setDefaults(defaults);
    }
 
源代码9 项目: sms-ticket   文件: NotificationUtil.java
private static void fireNotification(Context c, int notificationId, PendingIntent contentIntent,
                                     String title, String text,
                                     List<String> rows, String summary, String ticker, int smallIcon,
                                     int largeIcon,
                                     List<Action> actions, boolean keepNotification) {
    int defaults = Notification.DEFAULT_LIGHTS;
    if (Preferences.getBoolean(c, Preferences.NOTIFICATION_VIBRATE, true)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(title).setSmallIcon
        (smallIcon).setLargeIcon(BitmapFactory.decodeResource(c.getResources(), largeIcon))
        .setTicker(ticker).setContentText(text)
        .setLocalOnly(true)
        .setContentIntent(contentIntent).setWhen(System.currentTimeMillis()).setAutoCancel(!keepNotification)
        .setDefaults
            (defaults);

    String soundUri = Preferences.getString(c, Preferences.NOTIFICATION_RINGTONE, null);
    if (!TextUtils.isEmpty(soundUri)) {
        builder.setSound(Uri.parse(soundUri));
    }

    if (actions != null) {
        for (Action action : actions) {
            builder.addAction(action.drawable, c.getString(action.text), action.intent);
        }
    }

    Notification notification;
    if (rows == null) {
        notification = builder.build();
    } else {
        NotificationCompat.InboxStyle styled = new NotificationCompat.InboxStyle(builder);
        for (String row : rows) {
            styled.addLine(row);
        }
        styled.setSummaryText(summary);
        notification = styled.build();
    }

    NotificationManager nm = (NotificationManager)c.getSystemService(Context.NOTIFICATION_SERVICE);
    if (nm == null) {
        DebugLog.e("Cannot obtain notification manager");
        return;
    }

    nm.notify(notificationId, notification);
}
 
源代码10 项目: NotifyUtil   文件: BaseBuilder.java
public void build(){
      cBuilder = new NotificationCompat.Builder(NotifyUtil.context);
      cBuilder.setContentIntent(contentIntent);// 该通知要启动的Intent

      if(smallIcon >0){
          cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
      }
      if(bigIcon >0){
          cBuilder.setLargeIcon(BitmapFactory.decodeResource(NotifyUtil.context.getResources(), bigIcon));
      }

      cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息

      cBuilder.setContentTitle(contentTitle);// 设置通知中心的标题
      if(!TextUtils.isEmpty(contentText)){
          cBuilder.setContentText(contentText);// 设置通知中心中的内容
      }

      cBuilder.setWhen(System.currentTimeMillis());
      //cBuilder.setStyle()

/*
       * 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
 * 不设置的话点击消息后也不清除,但可以滑动删除
 */
      cBuilder.setAutoCancel(true);

      // 将Ongoing设为true 那么notification将不能滑动删除
      // notifyBuilder.setOngoing(true);
      /*
       * 从Android4.1开始,可以通过以下方法,设置notification的优先级,
 * 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
 */
      cBuilder.setPriority(priority);

      //int defaults = 0;

      if (sound) {
          defaults |= Notification.DEFAULT_SOUND;
      }
      if (vibrate) {
          defaults |= Notification.DEFAULT_VIBRATE;
      }
      if (lights) {
          defaults |= Notification.DEFAULT_LIGHTS;
      }
      cBuilder.setDefaults(defaults);


      //按钮
      if(btnActionBeens!=null && btnActionBeens.size()>0){
          for(BtnActionBean bean: btnActionBeens){
              cBuilder.addAction(bean.icon,bean.text,bean.pendingIntent);
          }
      }

      //headup
      if(headup){
          cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
          cBuilder.setDefaults(NotificationCompat.DEFAULT_ALL);
      }else {
          cBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
          cBuilder.setDefaults(NotificationCompat.DEFAULT_LIGHTS);
      }
      if(TextUtils.isEmpty(ticker)){
          cBuilder.setTicker("你有新的消息");
      }
      cBuilder.setOngoing(onGoing);
      cBuilder.setFullScreenIntent(fullscreenIntent,true);
      cBuilder.setVisibility(lockScreenVisiablity);

  }
 
源代码11 项目: AgentWebX5   文件: Notify.java
/**
	 * 设置在顶部通知栏中的各种信息
	 *
	 * @param pendingIntent
	 * @param smallIcon
	 * @param ticker
	 * @param pendingIntentCancel
	 */
	private void setCompatBuilder(PendingIntent pendingIntent, int smallIcon, String ticker,
	                              String title, String content, boolean sound, boolean vibrate, boolean lights, PendingIntent pendingIntentCancel) {
//        // 如果当前Activity启动在前台,则不开启新的Activity。
//        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//        // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
//        // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
//        PendingIntent pIntent = PendingIntent.getActivity(mContext,
//                requestCode, intent, FLAG);

		cBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
		cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
		cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息

		cBuilder.setContentTitle(title);// 设置通知中心的标题
		cBuilder.setContentText(content);// 设置通知中心中的内容
		cBuilder.setWhen(System.currentTimeMillis());

		/*
		 * 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
		 * 不设置的话点击消息后也不清除,但可以滑动删除
		 */
		cBuilder.setAutoCancel(true);
		// 将Ongoing设为true 那么notification将不能滑动删除
		// notifyBuilder.setOngoing(true);
		/*
		 * 从Android4.1开始,可以通过以下方法,设置notification的优先级,
		 * 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
		 */
		cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
		/*
		 * Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
		 * Notification.DEFAULT_SOUND:系统默认铃声。
		 * Notification.DEFAULT_VIBRATE:系统默认震动。
		 * Notification.DEFAULT_LIGHTS:系统默认闪光。
		 * notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
		 */
		int defaults = 0;

		cBuilder.setDeleteIntent(pendingIntentCancel);


		if (sound) {
			defaults |= Notification.DEFAULT_SOUND;
		}
		if (vibrate) {
			defaults |= Notification.DEFAULT_VIBRATE;
		}
		if (lights) {
			defaults |= Notification.DEFAULT_LIGHTS;
		}


		cBuilder.setDefaults(defaults);
	}
 
源代码12 项目: android-demo-xmpp-androidpn   文件: Notifier.java
public void notify(String notificationId, String apiKey, String title,
        String message, String uri) {
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (isNotificationEnabled()) {
        // Show the toast
        if (isNotificationToastEnabled()) {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }

        // Notification
        Notification notification = new Notification();
        notification.icon = getNotificationIcon();
        notification.defaults = Notification.DEFAULT_LIGHTS;
        if (isNotificationSoundEnabled()) {
            notification.defaults |= Notification.DEFAULT_SOUND;
        }
        if (isNotificationVibrateEnabled()) {
            notification.defaults |= Notification.DEFAULT_VIBRATE;
        }
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.when = System.currentTimeMillis();
        notification.tickerText = message;

        //            Intent intent;
        //            if (uri != null
        //                    && uri.length() > 0
        //                    && (uri.startsWith("http:") || uri.startsWith("https:")
        //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
        //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        //            } else {
        //                String callbackActivityPackageName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
        //                String callbackActivityClassName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
        //                intent = new Intent().setClassName(callbackActivityPackageName,
        //                        callbackActivityClassName);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            }

        Intent intent = new Intent(context,
                NotificationDetailsActivity.class);
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, title);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        intent.putExtra(Constants.NOTIFICATION_URI, uri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setLatestEventInfo(context, title, message,
                contentIntent);
        notificationManager.notify(random.nextInt(), notification);

        //            Intent clickIntent = new Intent(
        //                    Constants.ACTION_NOTIFICATION_CLICKED);
        //            clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        //            clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        //            clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title);
        //            clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        //            clickIntent.putExtra(Constants.NOTIFICATION_URI, uri);
        //            //        positiveIntent.setData(Uri.parse((new StringBuilder(
        //            //                "notif://notification.adroidpn.org/")).append(apiKey).append(
        //            //                "/").append(System.currentTimeMillis()).toString()));
        //            PendingIntent clickPendingIntent = PendingIntent.getBroadcast(
        //                    context, 0, clickIntent, 0);
        //
        //            notification.setLatestEventInfo(context, title, message,
        //                    clickPendingIntent);
        //
        //            Intent clearIntent = new Intent(
        //                    Constants.ACTION_NOTIFICATION_CLEARED);
        //            clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        //            clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        //            //        negativeIntent.setData(Uri.parse((new StringBuilder(
        //            //                "notif://notification.adroidpn.org/")).append(apiKey).append(
        //            //                "/").append(System.currentTimeMillis()).toString()));
        //            PendingIntent clearPendingIntent = PendingIntent.getBroadcast(
        //                    context, 0, clearIntent, 0);
        //            notification.deleteIntent = clearPendingIntent;
        //
        //            notificationManager.notify(random.nextInt(), notification);

    } else {
        Log.w(LOGTAG, "Notificaitons disabled.");
    }
}
 
源代码13 项目: opentasks   文件: Lights.java
public Lights()
{
    super(new Toggled(Notification.DEFAULT_LIGHTS, true, new NoSignal()));
}
 
源代码14 项目: BlackLight   文件: CommentTimeLineFetcherService.java
@Override
public void onHandleIntent(Intent intent) {
	Log.d(TAG, "service start");
	
	if (BaseApi.getAccessToken() == null) {
		BaseApi.setAccessToken(new LoginApiCache(this).getAccessToken());
		
		if (BaseApi.getAccessToken() == null) {
			return;
		}
	}
	
	CommentTimeLineApiCache cache = new CommentTimeLineApiCache(this);
	cache.loadFromCache();

	if (cache.mMessages.getSize() > 0) {
		CommentModel last = (CommentModel) cache.mMessages.get(0);
		CommentListModel since = CommentTimeLineApi.fetchCommentTimeLineSince(last.id);
		if (since != null && since.getSize() > 0) {
			cache.mMessages.addAll(true, since);
			cache.cache();

			int size = since.getSize();
			String str = String.format(getResources().getString(R.string.new_comment), size);

			Settings settings = Settings.getInstance(getApplicationContext());
			int defaults = (settings.getBoolean(Settings.NOTIFICATION_SOUND, true) ? Notification.DEFAULT_SOUND : 0)|
					(settings.getBoolean(Settings.NOTIFICATION_VIBRATE, true) ? Notification.DEFAULT_VIBRATE : 0)|
					Notification.DEFAULT_LIGHTS;
			
			PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, EntryActivity.class), 0);
			
			Notification n = new Notification.Builder(getApplicationContext())
			.setContentTitle(str)
			.setContentText(getString(R.string.click_to_view))
			.setSmallIcon(R.drawable.ic_action_chat)
			.setDefaults(defaults)
			.setAutoCancel(true)
			.setContentIntent(i)
			.build();
			
			NotificationManager m = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
			m.notify(ID, n);
		}
	}
	
	Log.d(TAG, "service finished");
}
 
源代码15 项目: opentasks   文件: Lights.java
public Lights(NotificationSignal original)
{
    super(new Toggled(Notification.DEFAULT_LIGHTS, true, original));
}
 
源代码16 项目: ESeal   文件: DownloadService.java
/**
     * 设置下载进度条Notification显示
     */
    private void setupNotificationDownloading(PendingIntent pendingIntent, int smallIcon, String ticker,
                                              String title, String content, boolean sound, boolean vibrate, boolean lights) {
//        // 如果当前Activity启动在前台,则不开启新的Activity。
//        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//        // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
//        // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
//        PendingIntent pIntent = PendingIntent.getActivity(mContext,
//                requestCode, intent, FLAG);
        notificationBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
        notificationBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
        notificationBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息

        notificationBuilder.setContentTitle(title);// 设置通知中心的标题
        notificationBuilder.setContentText(content);// 设置通知中心中的内容
        notificationBuilder.setWhen(System.currentTimeMillis());

		/*
         * 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
		 * 不设置的话点击消息后也不清除,但可以滑动删除
		 */
        notificationBuilder.setAutoCancel(false);
        // 将Ongoing设为true 那么notification将不能滑动删除
        // notifyBuilder.setOngoing(true);
        /*
         * 从Android4.1开始,可以通过以下方法,设置notification的优先级,
		 * 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
		 */
        notificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
        /*
         * Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
		 * Notification.DEFAULT_SOUND:系统默认铃声。
		 * Notification.DEFAULT_VIBRATE:系统默认震动。
		 * Notification.DEFAULT_LIGHTS:系统默认闪光。
		 * notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
		 */
        int defaults = 0;

        if (sound) {
            defaults |= Notification.DEFAULT_SOUND;
        }
        if (vibrate) {
            defaults |= Notification.DEFAULT_VIBRATE;
        }
        if (lights) {
            defaults |= Notification.DEFAULT_LIGHTS;
        }

        notificationBuilder.setDefaults(defaults);
    }
 
源代码17 项目: NotifyUtil   文件: NotifyUtil.java
/**
     * 设置在顶部通知栏中的各种信息
     *
     * @param pendingIntent
     * @param smallIcon
     * @param ticker
     */
    private void setCompatBuilder(PendingIntent pendingIntent, int smallIcon, String ticker,
                                  String title, String content, boolean sound, boolean vibrate, boolean lights) {
//        // 如果当前Activity启动在前台,则不开启新的Activity。
//        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//        // 当设置下面PendingIntent.FLAG_UPDATE_CURRENT这个参数的时候,常常使得点击通知栏没效果,你需要给notification设置一个独一无二的requestCode
//        // 将Intent封装进PendingIntent中,点击通知的消息后,就会启动对应的程序
//        PendingIntent pIntent = PendingIntent.getActivity(mContext,
//                requestCode, intent, FLAG);

        cBuilder.setContentIntent(pendingIntent);// 该通知要启动的Intent
        cBuilder.setSmallIcon(smallIcon);// 设置顶部状态栏的小图标
        cBuilder.setTicker(ticker);// 在顶部状态栏中的提示信息

        cBuilder.setContentTitle(title);// 设置通知中心的标题
        cBuilder.setContentText(content);// 设置通知中心中的内容
        cBuilder.setWhen(System.currentTimeMillis());

		/*
         * 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失,
		 * 不设置的话点击消息后也不清除,但可以滑动删除
		 */
        cBuilder.setAutoCancel(true);
        // 将Ongoing设为true 那么notification将不能滑动删除
        // notifyBuilder.setOngoing(true);
        /*
         * 从Android4.1开始,可以通过以下方法,设置notification的优先级,
		 * 优先级越高的,通知排的越靠前,优先级低的,不会在手机最顶部的状态栏显示图标
		 */
        cBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
        /*
         * Notification.DEFAULT_ALL:铃声、闪光、震动均系统默认。
		 * Notification.DEFAULT_SOUND:系统默认铃声。
		 * Notification.DEFAULT_VIBRATE:系统默认震动。
		 * Notification.DEFAULT_LIGHTS:系统默认闪光。
		 * notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
		 */
        int defaults = 0;

        if (sound) {
            defaults |= Notification.DEFAULT_SOUND;
        }
        if (vibrate) {
            defaults |= Notification.DEFAULT_VIBRATE;
        }
        if (lights) {
            defaults |= Notification.DEFAULT_LIGHTS;
        }

        cBuilder.setDefaults(defaults);
    }
 
源代码18 项目: adt-leanback-support   文件: NotificationCompat.java
/**
 * Set the default notification options that will be used.
 * <p>
 * The value should be one or more of the following fields combined with
 * bitwise-or:
 * {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE},
 * {@link Notification#DEFAULT_LIGHTS}.
 * <p>
 * For all default values, use {@link Notification#DEFAULT_ALL}.
 */
public Builder setDefaults(int defaults) {
    mNotification.defaults = defaults;
    if ((defaults & Notification.DEFAULT_LIGHTS) != 0) {
        mNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }
    return this;
}
 
源代码19 项目: guideshow   文件: NotificationCompat.java
/**
 * Set the default notification options that will be used.
 * <p>
 * The value should be one or more of the following fields combined with
 * bitwise-or:
 * {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE},
 * {@link Notification#DEFAULT_LIGHTS}.
 * <p>
 * For all default values, use {@link Notification#DEFAULT_ALL}.
 */
public Builder setDefaults(int defaults) {
    mNotification.defaults = defaults;
    if ((defaults & Notification.DEFAULT_LIGHTS) != 0) {
        mNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }
    return this;
}
 
源代码20 项目: android-recipes-app   文件: NotificationCompat.java
/**
 * Set the default notification options that will be used.
 * <p>
 * The value should be one or more of the following fields combined with
 * bitwise-or:
 * {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE},
 * {@link Notification#DEFAULT_LIGHTS}.
 * <p>
 * For all default values, use {@link Notification#DEFAULT_ALL}.
 */
public Builder setDefaults(int defaults) {
    mNotification.defaults = defaults;
    if ((defaults & Notification.DEFAULT_LIGHTS) != 0) {
        mNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }
    return this;
}