Search in sources :

Example 81 with NotificationManager

use of android.app.NotificationManager in project mobile-center-sdk-android by Microsoft.

the class Distribute method notifyDownload.

/**
     * Post notification about a completed download if we are in background when download completes.
     * If this method is called on app process restart or if application is in foreground
     * when download completes, it will not notify and return that the install U.I. should be shown now.
     *
     * @param releaseDetails release details to check state.
     * @param intent         prepared install intent.
     * @return false if install U.I should be shown now, true if a notification was posted or if the task was canceled.
     */
synchronized boolean notifyDownload(ReleaseDetails releaseDetails, Intent intent) {
    /* Check state. */
    if (releaseDetails != mReleaseDetails) {
        return true;
    }
    /*
         * If we already notified, that means this check was triggered by application being resumed,
         * thus in foreground at the moment the check download async task was started.
         *
         * We should not hold the install any longer now, even if the async task was long enough
         * for app to be in background again, we should show install U.I. now.
         */
    if (mForegroundActivity != null || getStoredDownloadState() == DOWNLOAD_STATE_NOTIFIED) {
        return false;
    }
    /* Post notification. */
    MobileCenterLog.debug(LOG_TAG, "Post a notification as the download finished in background.");
    Notification.Builder builder = new Notification.Builder(mContext).setTicker(mContext.getString(R.string.mobile_center_distribute_install_ready_title)).setContentTitle(mContext.getString(R.string.mobile_center_distribute_install_ready_title)).setContentText(getInstallReadyMessage()).setSmallIcon(mContext.getApplicationInfo().icon).setContentIntent(PendingIntent.getActivities(mContext, 0, new Intent[] { intent }, 0));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.setStyle(new Notification.BigTextStyle().bigText(getInstallReadyMessage()));
    }
    Notification notification = DistributeUtils.buildNotification(builder);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(DistributeUtils.getNotificationId(), notification);
    PreferencesStorage.putInt(PREFERENCE_KEY_DOWNLOAD_STATE, DOWNLOAD_STATE_NOTIFIED);
    /* Reset check download flag to show install U.I. on resume if notification ignored. */
    mCheckedDownload = false;
    return true;
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification)

Example 82 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by AOSPA.

the class MainActivity method cancelNotification.

private void cancelNotification() {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ID);
}
Also used : NotificationManager(android.app.NotificationManager)

Example 83 with NotificationManager

use of android.app.NotificationManager in project Space-Station-Tracker by Kiarasht.

the class Alert method onDestroy.

/**
     * When destroying the service make sure to get ride of any timers and notifications since
     * the user no longer wants them.
     */
@Override
public void onDestroy() {
    if (timer != null) {
        timer.cancel();
        timer.purge();
    }
    timer = null;
    NotificationManager nMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancel(NOTIFICATION_ID);
}
Also used : NotificationManager(android.app.NotificationManager)

Example 84 with NotificationManager

use of android.app.NotificationManager in project YourAppIdea by Michenux.

the class TutorialSyncAdapter method sendNotification.

private void sendNotification(WPJsonPost newPost) {
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(newPost.getUrl()));
    PendingIntent contentIntent = PendingIntent.getActivity(this.getContext(), 0, notificationIntent, 0);
    NotificationManager notificationManager = (NotificationManager) this.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this.getContext());
    notifBuilder.setContentTitle(getContext().getString(R.string.tutorial_notification_title));
    notifBuilder.setContentText(newPost.getTitle());
    notifBuilder.setSmallIcon(R.drawable.ic_stat_notify_newtuto);
    notifBuilder.setAutoCancel(true);
    notifBuilder.setDefaults(Notification.DEFAULT_SOUND);
    notifBuilder.setLights(0xff00ff00, 300, 1000);
    notifBuilder.setContentIntent(contentIntent);
    //notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(newPost.title));
    Notification noti = notifBuilder.build();
    //noti.ledARGB = 0xff00ff00;
    //noti.ledOnMS = 300;
    //noti.ledOffMS = 1000;
    //noti.flags |= Notification.FLAG_AUTO_CANCEL;
    //noti.flags |= Notification.FLAG_SHOW_LIGHTS;
    notificationManager.notify(0, noti);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 85 with NotificationManager

use of android.app.NotificationManager in project android_frameworks_base by AOSPA.

the class Tethering method showSoftApClientsNotification.

private void showSoftApClientsNotification(int icon) {
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        return;
    }
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
    CharSequence message;
    Resources r = Resources.getSystem();
    CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
    int size = mConnectedDeviceMap.size();
    if (size == 0) {
        message = r.getText(com.android.internal.R.string.tethered_notification_no_device_message);
    } else if (size == 1) {
        message = String.format((r.getText(com.android.internal.R.string.tethered_notification_one_device_message)).toString(), size);
    } else {
        message = String.format((r.getText(com.android.internal.R.string.tethered_notification_multi_device_message)).toString(), size);
    }
    if (softApNotificationBuilder == null) {
        softApNotificationBuilder = new Notification.Builder(mContext);
        softApNotificationBuilder.setWhen(0).setOngoing(true).setColor(mContext.getColor(com.android.internal.R.color.system_notification_accent_color)).setVisibility(Notification.VISIBILITY_PUBLIC).setCategory(Notification.CATEGORY_STATUS);
    }
    softApNotificationBuilder.setSmallIcon(icon).setContentTitle(title).setContentText(message).setContentIntent(pi).setPriority(Notification.PRIORITY_MIN);
    softApNotificationBuilder.setContentText(message);
    mLastSoftApNotificationId = icon + 10;
    notificationManager.notify(mLastSoftApNotificationId, softApNotificationBuilder.build());
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) Notification(android.app.Notification)

Aggregations

NotificationManager (android.app.NotificationManager)930 Intent (android.content.Intent)400 PendingIntent (android.app.PendingIntent)397 Notification (android.app.Notification)276 NotificationCompat (android.support.v4.app.NotificationCompat)267 NotificationChannel (android.app.NotificationChannel)129 Uri (android.net.Uri)62 Context (android.content.Context)59 SharedPreferences (android.content.SharedPreferences)41 Bitmap (android.graphics.Bitmap)41 Resources (android.content.res.Resources)39 Bundle (android.os.Bundle)36 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)35 SuppressLint (android.annotation.SuppressLint)27 TargetApi (android.annotation.TargetApi)26 TaskStackBuilder (android.app.TaskStackBuilder)25 StatusBarNotification (android.service.notification.StatusBarNotification)24 IOException (java.io.IOException)22 File (java.io.File)20 IntentFilter (android.content.IntentFilter)18