Java 类android.app.NotificationManager 实例源码

项目:pass_the_bomb    文件:PhoneService.java   
/**
 * Starts the service that controls the user actions performed on the phone
 * @param activity main game activity
 */
public static void startPhoneService(MainActivity activity) {
    isLocked = false;
    //the filters are the actions from the phone that we want to keep informed of
    IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    //must register a receiver in order to do things when filter actions are registered
    activity.mainRegisterReceiver(new UnlockReceiver(), filter); // TODO: Don't forget to unregister during onDestroy
    PhoneService.mainActivity = activity;

    mNotificationManager =
            (NotificationManager) mainActivity.getSystemService(Context.NOTIFICATION_SERVICE);
}
项目:FanChat    文件:QQDemoApplication.java   
private void showNotification(EMMessage emMessage) {
    String contentText = "";
    if (emMessage.getBody() instanceof EMTextMessageBody) {
        contentText = ((EMTextMessageBody) emMessage.getBody()).getMessage();
    }

    Intent chat = new Intent(this, ChatActivity.class);
    chat.putExtra(Constant.Extra.USER_NAME, emMessage.getUserName());
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, chat, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification.Builder(this)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.avatar1))
            .setSmallIcon(R.mipmap.ic_contact_selected_2)
            .setContentTitle(getString(R.string.receive_new_message))
            .setContentText(contentText)
            .setPriority(Notification.PRIORITY_MAX)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .build();
    notificationManager.notify(1, notification);
}
项目:MyAnimeViewer    文件:ManualAnimeUpdaterService.java   
@Override
public void onCreate() {
    // Start up the thread running the service.  Note that we create a
    // separate thread because the service normally runs in the process's
    // main thread, which we don't want to block.  We also make it
    // background priority so CPU-intensive work will not disrupt our UI.
    HandlerThread thread = new HandlerThread("ServiceStartArguments",
            Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotificationMap = new SparseIntArray();

    // Get the HandlerThread's Looper and use it for our Handler
    mServiceLooper = thread.getLooper();
    //mServiceHandler = new ServiceHandler(mServiceLooper);
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    setPrefs(PreferenceManager.getDefaultSharedPreferences(this));
}
项目:Phoenix-for-VK    文件:NewPostPushMessage.java   
private void notifyImpl(Context context, OwnerInfo info){
    String ownerName = fromId > 0 ? (stringEmptyIfNull(firstName) + " " + stringEmptyIfNull(lastName)) : groupName;
    final NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Utils.hasOreo()){
        nManager.createNotificationChannel(AppNotificationChannels.getNewPostChannel(context));
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.NEW_POST_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notify_statusbar)
            .setLargeIcon(info.getAvatar())
            .setContentTitle(context.getString(R.string.new_post_title))
            .setContentText(context.getString(R.string.new_post_was_published_in, ownerName))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
            .setAutoCancel(true);

    builder.setPriority(NotificationCompat.PRIORITY_HIGH);

    Intent intent = new Intent(context, MainActivity.class);
    intent.putExtra(Extra.PLACE, PlaceFactory.getPostPreviewPlace(accountId, postId, fromId));

    intent.setAction(MainActivity.ACTION_OPEN_PLACE);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(context, fromId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(contentIntent);
    Notification notification = builder.build();

    configOtherPushNotification(notification);

    nManager.notify(String.valueOf(fromId), NotificationHelper.NOTIFICATION_NEW_POSTS_ID, notification);
}
项目:humaniq-android    文件:FcmListenerService.java   
private void createNotification(String message, String title) {
    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(title)
            .setContentText(message)
            .setAutoCancel(true)
            .setSmallIcon(R.drawable.cake)  // TODO: change icon
            .setSound(defaultSoundUri);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP)
        notificationBuilder.setColor(0xff023876);

    NotificationManager notificationManager = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}
项目:immersify    文件:ToggleNotification.java   
public static void show(Context context) {
    // Build toggle action
    Intent notificationServiceIntent = new Intent(context, NotificationService.class);
    notificationServiceIntent.setAction(ACTION_TOGGLE);
    PendingIntent notificationPendingIntent = PendingIntent.getService(context, 0, notificationServiceIntent, 0);
    NotificationCompat.Action toggleAction = new NotificationCompat.Action(
            R.drawable.ic_border_clear_black_24dp,
            "Toggle",
            notificationPendingIntent
    );

    // Build notification
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_zoom_out_map_black_24dp)
                    .setContentTitle("Immersify")
                    .setContentText("Tap to toggle immersive mode")
                    .setContentIntent(notificationPendingIntent)
                    .setPriority(NotificationCompat.PRIORITY_MIN)
                    .setCategory(NotificationCompat.CATEGORY_SERVICE)
                    .addAction(toggleAction)
                    .setOngoing(true);

    // Clear existing notifications
    ToggleNotification.cancel(context);

    // Notify the notification manager to create the notification
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
项目:Android-Wear-Projects    文件:WearStepService.java   
private void updateNotification() {
    // Create a notification builder that's compatible with platforms >= version 4
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getApplicationContext());

    // Set the title, text, and icon
    builder.setContentTitle(getString(R.string.app_name))
            .setSmallIcon(R.drawable.ic_step_icon);

    builder.setContentText("steps: " + StepsTaken.getSteps());

    // Get an instance of the Notification Manager
    NotificationManager notifyManager = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);

    // Build the notification and post it
    notifyManager.notify(0, builder.build());
}
项目:quake-alert-android-app    文件:MyFirebaseMessagingService.java   
/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, QuakeActivity.class);//**The activity that you want to open when the notification is clicked
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_outline_white_24dp)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
项目:Keyguard    文件:MaskWindowUtils.java   
private void dismissKeyguardView () {
    try {
        mManager.removeView(mKeyguardView);
        mContext.sendBroadcast(new Intent(KeyguardLiveActivity.ACTION_DISMISS));
        Notification finishNotification = new NotificationCompat.Builder(mContext)
                .setContentTitle(mContext.getString(R.string.notification_finish_title))
                .setContentText(mContext.getString(R.string.notification_finish_text,
                        Utils.formatSecToStr(BigDecimal.valueOf(mUsedTime)),
                                String.valueOf(mScreenOn)))
                .setSmallIcon(R.drawable.ic_stat_lock_open)
                .setVibrate(new long[]{300})
                .build();
        ((NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE))
                .notify(0, finishNotification);
    } catch (Exception e) {
        e.printStackTrace();
        android.os.Process.killProcess(
                android.os.Process.myPid()
        );
    }
}
项目:GodotFireBase    文件:BaseTaskService.java   
/**
 * Show notification with a progress bar.
 */
protected void showProgressNotification(String caption, long completedUnits, long totalUnits) {
    int percentComplete = 0;
    if (totalUnits > 0) { percentComplete = (int) (100 * completedUnits / totalUnits); }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_file_upload_white_24dp)
    .setContentTitle(getString(R.string.godot_project_name_string))
    .setContentText(caption)
    .setProgress(100, percentComplete, false)
    .setOngoing(true)
    .setAutoCancel(false);

    NotificationManager manager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    manager.notify(PROGRESS_NOTIFICATION_ID, builder.build());
}
项目:chalkboard    文件:Background.java   
@TargetApi(26)
private void createNotificationChannel() {

    notificationChannelClass = new NotificationChannel("class", "Class Notifications", NotificationManager.IMPORTANCE_LOW);
    notificationChannelClass.setDescription("Notifications about classes.");
    notificationChannelClass.enableLights(false);
    notificationChannelClass.enableVibration(false);
    notificationChannelClass.setBypassDnd(false);
    notificationChannelClass.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelClass.setShowBadge(false);

    notificationManager.createNotificationChannel(notificationChannelClass);

    notificationChannelReminder = new NotificationChannel("reminder", "Reminders", NotificationManager.IMPORTANCE_MAX);
    notificationChannelReminder.setDescription("Notifications about events.");
    notificationChannelReminder.enableLights(true);
    notificationChannelReminder.setLightColor(sharedPreferences.getInt("primary_color", ContextCompat.getColor(this, R.color.teal)));
    notificationChannelReminder.enableVibration(true);
    notificationChannelReminder.setBypassDnd(true);
    notificationChannelReminder.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelReminder.setShowBadge(true);

    notificationManager.createNotificationChannel(notificationChannelReminder);

}
项目:captcha    文件:EditTextDialog.java   
private void addNotification(Context context, String title, String message) {
    //获取通知管理器服务
    notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent pendingIntent = createDisplayMessageIntent(context, message, Utils.getNotificationId());
    //新建一个notification
    Notification.Builder builder = new Notification.Builder(context)
            .setTicker(message)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(title)
            .setContentText(message)
            .setSmallIcon(R.drawable.ic_notification)
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentIntent(pendingIntent);
    builder.setFullScreenIntent(pendingIntent, true);
    //开始通知
    notificationManager.notify(Utils.getNotificationId(), builder.getNotification());
}
项目:Cable-Android    文件:MessageNotifier.java   
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();
    }
  }
}
项目:Nird2    文件:StartupFailureActivity.java   
private void handleIntent(Intent i) {
    StartResult result = (StartResult) i.getSerializableExtra("briar.START_RESULT");
    int notificationId = i.getIntExtra("briar.FAILURE_NOTIFICATION_ID", -1);

    // cancel notification
    if (notificationId > -1) {
        Object o = getSystemService(NOTIFICATION_SERVICE);
        NotificationManager nm = (NotificationManager) o;
        nm.cancel(notificationId);
    }

    // show proper error message
    TextView view = (TextView) findViewById(R.id.errorView);
    if (result.equals(StartResult.DB_ERROR)) {
        view.setText(getText(R.string.startup_failed_db_error));
    } else if (result.equals(StartResult.SERVICE_ERROR)) {
        view.setText(getText(R.string.startup_failed_service_error));
    }
}
项目:MTweaks-KernelAdiutorMOD    文件:UtilsDisplay.java   
static void showUpdateNotAvailableNotification(Context context, String title, String content, int smallIconResourceId) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentIntent(contentIntent)
            .setContentTitle(title)
            .setContentText(content)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setSmallIcon(smallIconResourceId)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setOnlyAlertOnce(true)
            .setAutoCancel(true);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
项目:1617PROJ1Bloeddonatie-app    文件:GeofenceService.java   
private void sendNotification(String text) {
    Intent intent = new Intent(this, MapsActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("Bloeddonatie")
        .setContentText(text)
        .setAutoCancel(true)
        .setSound(notificationSound)
        .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notifiBuilder.build());
}
项目:TFG-SmartU-La-red-social    文件:MyFirebaseMessagingService.java   
/**
 * Muestra que ha habido una nueva notificación
 * @param notification
 * @param data
 */
private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("notificacion","notificacion");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(notification.getTitle())
            .setContentText(notification.getBody())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setSmallIcon(R.mipmap.ic_launch)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}
项目:boohee_v5.6    文件:StatusPostTextActivity.java   
private void init() {
    this.mActivity = this;
    this.mNotificationManager = (NotificationManager) getSystemService("notification");
    this.mNFBuilder = new Builder(this.ctx);
    this.group_id = getIntExtra(Const.GROUP_ID);
    ArrayList<String> tempList = getIntent().getStringArrayListExtra(KEY_SELECTED_PICTURES);
    if (tempList != null && tempList.size() > 0) {
        this.mSelectPictures.clear();
        this.mSelectPictures.addAll(0, tempList);
        this.mSelectPictures.add("add");
    }
    initSendApi();
    if (getIntent() != null) {
        this.attachMent = (AttachMent) getIntent().getParcelableExtra(EXTRA_ATTACHMENT);
    }
    restoreDraft();
    initPicGridView();
    if (this.attachMent != null) {
        this.attachmentLayout.setVisibility(0);
        this.imageLoader.displayImage(this.attachMent.pic, this.ivAttachment);
        this.tvAttachment.setText(this.attachMent.title);
    }
    initEmoji();
    handlePictureURL();
}
项目:Tech-Jalsa    文件:NotificationUtils.java   
private void showSmallNotification(NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent) {
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.addLine(message);
    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setStyle(inboxStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.drawable.logo)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Config.NOTIFICATION_ID, notification);
}
项目:AlarmWithL-T    文件:TestReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder( context );

    builder.setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Test")
            .setContentText( intent.getStringExtra("text") )
            .setSubText("Three Line")
            .setContentInfo("info")
            .setWhen( System.currentTimeMillis() );

    manager.notify(0, builder.build());
    Log.d("onReceive", "はいったお!!!!!!!!");

}
项目:FCM-for-Mojo    文件:NotificationBuilderImplBase.java   
/**
 * 分组消息的头部
 **/
private void notifyGroupSummary(Context context, Chat chat, NotificationBuilder nb) {
    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = createBuilder(context, null)
            .setChannelId(NOTIFICATION_CHANNEL_GROUP_SUMMARY)
            .setSubText(String.format(context.getString(R.string.notification_messages_multi_sender), nb.getMessageCount(), nb.getSendersCount()))
            .setShowWhen(true)
            .setWhen(System.currentTimeMillis())
            .setGroup(GROUP_KEY)
            .setGroupSummary(true)
            .setContentIntent(NotificationBuilder.createContentIntent(context, 0, null))
            .setDeleteIntent(NotificationBuilder.createDeleteIntent(context, 0, null));

    notificationManager.notify(NOTIFICATION_ID_GROUP_SUMMARY, builder.build());
}
项目:aos-MediaLib    文件:NetworkScannerServiceVideo.java   
/** removes files from our db */
private void doRemoveFiles(Uri data) {
    if (DBG) Log.d(TAG, "doRemoveFiles " + data);
    if (data == null) return;
    ContentResolver cr = getContentResolver();

    String path = data.toString();
    String[] selectionArgs = { path };
    // send out a sticky broadcast telling the world that we started scanning
    Intent scannerIntent = new Intent(ArchosMediaIntent.ACTION_VIDEO_SCANNER_SCAN_STARTED, data);
    sendStickyBroadcast(scannerIntent);
    // also show a notification.
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification(nm, data.toString(), R.string.network_unscan_msg);

    int deleted = cr.delete(VideoStoreInternal.FILES_SCANNED, IN_FOLDER_SELECT, selectionArgs);
    Log.d(TAG, "removed: " + deleted);

    // cancel the sticky broadcast
    removeStickyBroadcast(scannerIntent);
    // send a "done" notification
    sendBroadcast(new Intent(ArchosMediaIntent.ACTION_VIDEO_SCANNER_SCAN_FINISHED, data));
    // and cancel the Notification
    hideNotification(nm);
}
项目:iosched-reader    文件:AnnouncementCommand.java   
private void displayNotification(Context context, String message) {
    LOGI(TAG, "Displaying notification: " + message);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify(0, new NotificationCompat.Builder(context)
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.drawable.ic_stat_notification)
                    .setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name))
                    .setContentText(message)
                    //.setColor(context.getResources().getColor(R.color.theme_primary))
                        // Note: setColor() is available in the support lib v21+.
                        // We commented it out because we want the source to compile 
                        // against support lib v20. If you are using support lib
                        // v21 or above on Android L, uncomment this line.
                    .setContentIntent(
                            PendingIntent.getActivity(context, 0,
                                    new Intent(context, MyScheduleActivity.class)
                                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                                                    Intent.FLAG_ACTIVITY_SINGLE_TOP),
                                    0))
                    .setAutoCancel(true)
                    .build());
}
项目:Crimson    文件:NotificationService.java   
private void screenAlertMessage(Context context, String msg) {

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle("Relax your eyes a little bit.")
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setVibrate(new long[0])
                        .setAutoCancel(true)
                        .setContentText(msg);

        int mNotificationId = 001;

        NotificationManager mNotifyMgr =
                (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
        mNotifyMgr.notify(mNotificationId, mBuilder.build());

    }
项目:Botanist    文件:FertilizerReceiver.java   
/**
 * Receiver received an update
 * @param context - current app context
 * @param intent - intent that updated height
 */
@Override
public void onReceive(Context context, Intent intent) {
    String name = intent.getExtras().getString("name");
    String plantId = intent.getExtras().getString("plant_id");
    int notificationId = intent.getExtras().getInt("id");
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_botanist_big);
    Intent resultIntent = new Intent(context, LoginActivity.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context, "default").setSmallIcon(R.drawable.ic_poop_notification)
                    .setLargeIcon(largeIcon)
                    .setDefaults(Notification.DEFAULT_SOUND).setContentTitle(name + " May Need Fertilizer")
                    .setContentText("Keep track of " + name + " fertilization record")
                    .setAutoCancel(true).setContentIntent(resultPendingIntent);
    NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    if (mNotifyMgr != null) {
        mNotifyMgr.notify(notificationId, mBuilder.build());
    }
    DatabaseManager.getInstance().updateNotificationTime(plantId, "lastFertilizerNotification");
}
项目:AutoVolume    文件:MainActivity.java   
private void notification() {

        notification = new NotificationCompat.Builder(this);
       notification.setSmallIcon(R.drawable.sound);
        notification.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
                R.drawable.sound));
        notification.setTicker("Auto Volume");
        notification.setOngoing(true);
        notification.setContentTitle("Go to Auto Volume");
        notification.setWhen(System.currentTimeMillis());

        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setContentIntent(pendingIntent);

        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(uniqueID, notification.build());

    }
项目:DoNotDisturbSync    文件:WearMessageListenerService.java   
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_PREFIX)) {
        // Read the received ringer or dnd mode and convert it back to an integer
        int newMode = Integer.parseInt(new String(messageEvent.getData()));

        if (SEND_RINGER_MODE) {
            Log.d(TAG, "Received new ringer mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        } else {
            Log.d(TAG, "Received new dnd mode " + newMode + " from source " + messageEvent.getSourceNodeId());
        }

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Check if the notification policy access has been granted for the app
        // This is needed to set modes that affect Do Not Disturb in Android N
        if (mNotificationManager.isNotificationPolicyAccessGranted()) {
            if (SEND_RINGER_MODE) {
                Log.d(TAG, "Attempting to set ringer mode " + newMode);

                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

                if (newMode == AudioManager.RINGER_MODE_SILENT) {
                    audioManager.setRingerMode(newMode);
                } else {
                    // Set the saved "normal" value
                    audioManager.setRingerMode(getNormalRingerMode());
                }
            } else {
                Log.d(TAG, "Attempting to set dnd mode " + newMode);

                mNotificationManager.setInterruptionFilter(newMode);
            }
        } else {
            Log.d(TAG, "App is not allowed to change Do Not Disturb mode without applying workaround");
        }
    } else {
        super.onMessageReceived(messageEvent);
    }
}
项目:Hitalk    文件:NotificationUtils.java   
public static void showNotification(Context context, String title, String content, String sound, Intent intent) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 1, intent, 0);
    NotificationCompat.Builder mBuilder = (new NotificationCompat.Builder(context)).setSmallIcon(context.getApplicationInfo().icon).setContentTitle(title).setAutoCancel(true).setContentIntent(contentIntent).setDefaults(3).setContentText(content);
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    if(sound != null && sound.trim().length() > 0) {
        notification.sound = Uri.parse("android.resource://" + sound);
    }

    manager.notify(1, notification);
}
项目:Nird2    文件:AndroidNotificationManagerImpl.java   
@UiThread
private void clearBlogPostNotification() {
    blogCounts.clear();
    blogTotal = 0;
    Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
    NotificationManager nm = (NotificationManager) o;
    nm.cancel(BLOG_POST_NOTIFICATION_ID);
}
项目:Trinity-App    文件:NotifAlarmReceiver.java   
public void createNotif() {
    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    String eventName = eventsForNotif[0];
    if (counterForCurrentEventsForNotif > 1) {
        for (int i = 1; i < counterForEventsForNotif; i++) {
            if (i == counterForCurrentEventsForNotif - 1)
                eventName = eventName + " and " + currentEventsForNotif[i];
            else
                eventName = eventName + ", " + currentEventsForNotif[i];
        }
    }

    Uri notifRing = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone ringtone =RingtoneManager.getRingtone(context, notifRing);
    ringtone.play();
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(500);

    Log.d("alarm","ture");
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_calendar)
            .setContentTitle("Trinity")
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .setContentText(eventName + " scheduled for today.");
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    int mNotifId = 1;
    manager.notify(mNotifId, builder.build());
}
项目:lineagex86    文件:ZenAccessSettings.java   
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mContext = getActivity();
    mPkgMan = mContext.getPackageManager();
    mNoMan = mContext.getSystemService(NotificationManager.class);
    setPreferenceScreen(getPreferenceManager().createPreferenceScreen(mContext));
}
项目:Nird2    文件:AndroidNotificationManagerImpl.java   
@UiThread
private void updateBlogPostNotification() {
    if (blogTotal == 0) {
        clearBlogPostNotification();
    } else if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) {
        NotificationCompat.Builder b =
                new NotificationCompat.Builder(appContext);
        b.setSmallIcon(R.drawable.notification_blog);
        b.setColor(ContextCompat.getColor(appContext,
                R.color.briar_primary));
        b.setContentTitle(appContext.getText(R.string.app_name));
        b.setContentText(appContext.getResources().getQuantityString(
                R.plurals.blog_post_notification_text, blogTotal,
                blogTotal));
        String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
        if (!StringUtils.isNullOrEmpty(ringtoneUri))
            b.setSound(Uri.parse(ringtoneUri));
        b.setDefaults(getDefaults());
        b.setOnlyAlertOnce(true);
        b.setAutoCancel(true);
        // Touching the notification shows the combined blog feed
        Intent i = new Intent(appContext, NavDrawerActivity.class);
        i.putExtra(INTENT_BLOGS, true);
        i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
        i.setData(Uri.parse(BLOG_URI));
        TaskStackBuilder t = TaskStackBuilder.create(appContext);
        t.addParentStack(NavDrawerActivity.class);
        t.addNextIntent(i);
        b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
        if (Build.VERSION.SDK_INT >= 21) {
            b.setCategory(CATEGORY_SOCIAL);
            b.setVisibility(VISIBILITY_SECRET);
        }
        Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
        NotificationManager nm = (NotificationManager) o;
        nm.notify(BLOG_POST_NOTIFICATION_ID, b.build());
    }
}
项目:MyBP    文件:NotificationService.java   
@SuppressWarnings("deprecation")
private void raiseNotification() {
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("MyBP reminder");
    builder.setSmallIcon(R.drawable.ic_dashboard_grey_700_24dp);
    builder.setColor(this.getResources().getColor(R.color.teal));
    builder.setContentTitle("MyBP");
    builder.setContentText("MyBP periodic reminder");
    builder.setContentIntent(pendingIntent);
    builder.setAutoCancel(true);

    if(numNots == 0)
        ++numNots;
    else
        builder.setNumber(++numNots);

    if(setSoundNotification) {
        builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }

    if(setLightNotification) {
        builder.setLights(this.getResources().getColor(R.color.teal), 2000, 2000);
    }

    if(setVibrationsNotification) {
        builder.setVibrate(new long[]{250, 500, 250, 500, 250, 500});
    }

    NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, builder.build());
}
项目:ITagAntiLost    文件:NotifyManager.java   
static void showNotification(DeviceDB device, Context context, String message) {
  Bitmap bitmap = Device.getBitmapImage(device.getImage(), context.getResources());
  ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
      .notify((int) Device.doHash(device.getAddress()),
          new NotificationCompat.Builder(context)
              .setLargeIcon(bitmap)
              .setSmallIcon(R.drawable.ic_find_key)
              .setContentTitle(context.getString(R.string.app_name))
              .setVibrate(new long[]{1000, 1000})
              .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
              .setContentText(message)
              .build());
}
项目:aos-FileCoreLibrary    文件:FileTransferService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
 // configure the notification
    notificationBuilder = new Notification.Builder(this);
    contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_progress);
    contentView.setImageViewResource(R.id.image, R.drawable.ic_wifip2p);
    contentView.setTextViewText(R.id.title, "Waiting for connection to download");
    contentView.setProgressBar(R.id.status_progress, 100, 0, false);
    notificationBuilder.setContent(contentView);
    notificationBuilder.setSmallIcon(R.drawable.ic_wifip2p);
    notificationBuilder.setOngoing(true);
    notificationBuilder.setTicker("WiFi Direct service started");
    notificationBuilder.setOnlyAlertOnce(true);

    Intent i = new Intent(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    boolean client = false;
    if (intent != null && intent.hasExtra("client"))
        client = intent.getBooleanExtra("client", false);
    if (intent != null && intent.hasExtra("path"))
        path = intent.getStringExtra("path");
    i.setComponent(new ComponentName("com.archos.wifidirect",
            client ? "com.archos.wifidirect.WiFiDirectSenderActivity" : "com.archos.wifidirect.WiFiDirectReceiverActivity"));
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(pi);
    notificationManager = (NotificationManager) getApplicationContext().getSystemService(
            Context.NOTIFICATION_SERVICE);
    //To not be killed
    startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
    return START_STICKY;
}
项目:1946    文件:GcmPush.java   
public void deliverStoredMessages()
{
    final SharedPreferences prefs = getGcmPreferences(mContext);
    int messageCount = prefs.getInt(PROPERTY_MESSAGE_COUNT, 0);
    Log.i("yoyo", "GCM: sending " + messageCount + " stored messages");

    if( messageCount > 0 )
    {
        for( int i = 1; i <= messageCount; ++i)
        {
            String keyData = PROPERTY_MESSAGE_N + Integer.toString(i);
            String keyType = PROPERTY_MESSAGE_TYPE_N + Integer.toString(i);
            String data = prefs.getString(keyData, "");
            int msgType = prefs.getInt(keyType, PUSH_EVENT_REMOTE);
            RunnerJNILib.GCMPushResult( data, msgType, true );
        }
    }

    //remove the messages
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(PROPERTY_MESSAGE_COUNT, 0);
    for( int i = 0; i < messageCount; ++i)
    {
        String key = PROPERTY_MESSAGE_N + Integer.toString(i);
        editor.remove(key);
    }
    editor.commit();

    //we can remove notifications now, since we have delivered all the data to the app
    NotificationManager notificationManager = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}
项目:bluewatcher    文件:StatusBarNotificationManager.java   
public StatusBarNotificationManager(Activity parentActivity) {
    this.activity = parentActivity;
    notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
    currentStatus = Status.Disconnected;
    currentControlMode = activity.getApplicationContext().getString(R.string.not_available);
    update();
}
项目:Nird2    文件:AndroidNotificationManagerImpl.java   
@UiThread
private void clearForumPostNotification() {
    forumCounts.clear();
    forumTotal = 0;
    Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
    NotificationManager nm = (NotificationManager) o;
    nm.cancel(FORUM_POST_NOTIFICATION_ID);
}
项目:StartBluetooth    文件:Service.java   
private void displayNotification(Context context, String message) {
    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        Toast.makeText(context, "StartBluetooth: Unable to get NotificationManager", Toast.LENGTH_SHORT).show();
        return;
    }

    notificationManager.notify(notificationID, new NotificationCompat.Builder(context).setSmallIcon(R.mipmap.ic_launcher).setContentTitle("StartBluetooth").setContentText(message).build());
    notificationID++;
}
项目:Veggietizer    文件:NotificationService.java   
@Override
public void onCreate() {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    /* Unneeded due to setAutoCancel(true):

    Intent onNotificationDeletedIntent = new Intent(getApplicationContext(), OnNotificationDeletedReceiver.class);
    PendingIntent onNotificationDeletedPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
                onNotificationDeletedIntent, 0);*/
    NotificationCompat.Builder reminderBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_statusbar)
            .setContentTitle(getString(R.string.reminder_title))
            .setContentText(getString(R.string.reminder_description))
            .setPriority(NotificationCompat.PRIORITY_LOW)
            //.setDeleteIntent(onNotificationDeletedPendingIntent)
            .setAutoCancel(true);
    Intent inputIntent = new Intent(this , InputActivity.class);
    Intent overviewIntent = new Intent(this , OverviewActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this)
        .addNextIntentWithParentStack(overviewIntent)
        .addNextIntentWithParentStack(inputIntent);
    PendingIntent inputPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    inputIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    inputIntent.putExtra(ViewConstants.CALLER_ACTIVITY, ViewConstants.OVERVIEW_ACTIVITY);
    reminderBuilder.setContentIntent(inputPendingIntent);
    notificationManager.notify(NOTIFICATION_ID_REMINDER, reminderBuilder.build());

    PreferencesAccess.storeDate(getApplicationContext(), PreferencesAccess.NOTIFICATION_PREFS,
            PreferencesAccess.KEY_DATE_REMINDER_LAST_SHOWN, Calendar.getInstance().getTime());

    stopSelf();
}