Example usage for android.support.v4.app NotificationManagerCompat from

List of usage examples for android.support.v4.app NotificationManagerCompat from

Introduction

In this page you can find the example usage for android.support.v4.app NotificationManagerCompat from.

Prototype

public static NotificationManagerCompat from(Context context) 

Source Link

Usage

From source file:com.sleekcoder.weardemo.DismissListener.java

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                NotificationManagerCompat.from(this).cancel(Constants.BOTH_ID);
            }//from  w w  w  .j a v a2s.  c o  m
        }
    }
}

From source file:com.siddique.androidwear.today.GeofenceTransitionsIntentService.java

/**
 * ? ?? /* www.j a v  a  2  s. c  om*/
 *
 * @param intent ?   ??. ? ?? addGeofences()  ?  PendingIntent ? ??  ? ? ?.
 */
@Override
protected void onHandleIntent(Intent intent) {
    Log.i(TAG, "Location changed " + intent);

    GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);
    if (geoFenceEvent.hasError()) {
        int errorCode = geoFenceEvent.getErrorCode();
        Log.e(TAG, "Location Services error: " + errorCode);
    } else {

        int transitionType = geoFenceEvent.getGeofenceTransition();
        // NotificationManager ? ? 
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

        Log.i(TAG, "Notifying home todo items");
        String triggeredGeoFenceId = geoFenceEvent.getTriggeringGeofences().get(0).getRequestId();

        switch (triggeredGeoFenceId) {
        case Constants.HOME_GEOFENCE_ID:
            if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) {
                Log.i(TAG, "Notifying home todo items");
                notifyTodoItems(notificationManager, "Home", Constants.HOME_TODO_NOTIFICATION_ID,
                        R.drawable.white_house);
            }
            break;
        case Constants.WORK_GEOFENCE_ID:
            if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) {
                Log.i(TAG, "Notifying work todo items");
                notifyTodoItems(notificationManager, "Work", Constants.WORK_TODO_NOTIFICATION_ID,
                        R.drawable.capitol_hill);
            }
            break;
        }
    }
}

From source file:com.hodor.company.areminder.service.TimerService.java

private void showAlarm(int category) {
    final Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = { 0, getResources().getInteger(R.integer.vibration_duration) };
    v.vibrate(pattern, -1);/*  w ww. j a  v a  2s . c o m*/
    Intent intent = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .putExtra(MainActivity.ACTION_REMOVE_TIMER, 1);
    startActivity(intent);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    Notification notification = NotificationCenter.getNotificationCenter(this)
            .buildFinishNotification(category);
    notificationManager.notify(MainActivity.END_NOTIFICATION_ID, notification);
}

From source file:com.android.messaging.sms.SmsStorageStatusManager.java

/**
 * Cancel the notification/*ww w  .  j a v a 2  s  .c om*/
 */
public static void cancelStorageLowNotification() {
    final NotificationManagerCompat notificationManager = NotificationManagerCompat
            .from(Factory.get().getApplicationContext());
    notificationManager.cancel(getNotificationTag(), PendingIntentConstants.SMS_STORAGE_LOW_NOTIFICATION_ID);
}

From source file:com.irateam.vkplayer.notifications.DownloadNotification.java

public static void errorSync(Context context, String error) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification_sync_problem_white_24dp)
            .setContentTitle(context.getString(R.string.notification_error_sync_title)).setContentText(
                    error.isEmpty() ? context.getString(R.string.notification_error_sync_message) : error);
    NotificationManagerCompat.from(context).notify(FINAL_SYNC_NOTIFICATION_ID, builder.build());
}

From source file:com.hacktx.android.services.NotificationService.java

private void sendBundledNotification(String group, Map<String, String> data) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    int id = NotificationUtils.getId(this, group);
    String title = data.get("title") != null ? data.get("title") : getString(R.string.app_name);
    String text = data.get("text") != null ? data.get("text") : getString(R.string.notif_new_notifications);
    boolean vibrate = Boolean.parseBoolean(data.get("vibrate") != null ? data.get("vibrate") : "false");

    NotificationCompat.Builder summaryNotifBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_alert).setGroup(group).setGroupSummary(true)
            .setColor(ContextCompat.getColor(this, R.color.primary))
            .setContentTitle(getString(R.string.app_name)).setAutoCancel(true).setContentIntent(pendingIntent);

    notificationManager.notify(NotificationUtils.getIdBase(this, group), summaryNotifBuilder.build());

    NotificationCompat.Builder notificationBuilder = getBaseNotificationBuilder(title, text, vibrate)
            .setContentIntent(pendingIntent).setGroup(group);

    notificationManager.notify(id, notificationBuilder.build());
}

From source file:com.android.deskclock.alarms.AlarmNotifications.java

public static void showLowPriorityNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */))
            .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true);

    // Setup up hide notification
    Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DELETE_TAG,
            instance, AlarmInstance.HIDE_NOTIFICATION_STATE);
    notification.setDeleteIntent(PendingIntent.getService(context, instance.hashCode(), hideIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
    notification.addAction(R.drawable.ic_alarm_off_24dp,
            context.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getService(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    Intent viewAlarmIntent = createViewAlarmIntent(context, instance);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(instance.hashCode(), notification.build());
}

From source file:com.amlcurran.messages.notifications.Notifier.java

public Notifier(Context context) {
    this.preferenceStore = new SharedPreferenceStore(context);
    this.loader = SingletonManager.getConversationLoader(context);
    this.photoLoader = SingletonManager.getPhotoLoader(context);
    this.notificationManager = NotificationManagerCompat.from(context);
    this.notificationBuilder = new NotificationBuilder(context, new SharedPreferenceStore(context));
    this.postedConversations = new ArrayList<Conversation>();
}

From source file:id.satusatudua.sigap.service.LocationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (!BenihUtils.isMyServiceRunning(context, LocationService.class)) {
        context.startService(new Intent(context, LocationService.class));
    }// www .j av a2 s . c om

    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean anyLocationProv = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    anyLocationProv |= locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    if (!anyLocationProv) {
        Notification notification = new NotificationCompat.Builder(context).setContentTitle("Sigap")
                .setContentText("Fitur lokasi tidak aktif.")
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
                .setSmallIcon(R.mipmap.ic_launcher).setOngoing(true).setAutoCancel(true)
                .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle()
                        .bigText("Aktifkan fitur lokasi agar Sigap bisa berjalan dengan baik."))
                .build();

        NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).notify(25061993, notification);
    } else {
        NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).cancel(25061993);
    }
}

From source file:net.olejon.mdapp.NotificationsFromSlvActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Settings/*from w  ww .j ava2  s .c  o  m*/
    PreferenceManager.setDefaultValues(mContext, R.xml.settings, false);

    // Connected?
    if (!mTools.isDeviceConnected()) {
        mTools.showToast(getString(R.string.device_not_connected), 1);

        finish();

        return;
    }

    // Notification manager
    mNotificationManagerCompat = NotificationManagerCompat.from(mContext);

    // Layout
    setContentView(R.layout.activity_notifications_from_slv);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.notifications_from_slv_toolbar);
    toolbar.setTitle(getString(R.string.notifications_from_slv_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.notifications_from_slv_toolbar_progressbar);
    mProgressBar.setVisibility(View.VISIBLE);

    // Refresh
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.notifications_from_slv_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green,
            R.color.accent_purple, R.color.accent_orange);

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            getNotifications(false);
        }
    });

    // Recycler view
    mRecyclerView = (RecyclerView) findViewById(R.id.notifications_from_slv_cards);

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(new NotificationsFromSlvAdapter(mContext, new JSONArray()));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));

    // Get notifications
    getNotifications(true);
}