Search in sources :

Example 11 with Notification

use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method setProvNotificationVisible.

private void setProvNotificationVisible(boolean visible, int networkType, String extraInfo, String url) {
    if (DBG) {
        log("setProvNotificationVisible: E visible=" + visible + " networkType=" + networkType + " extraInfo=" + extraInfo + " url=" + url);
    }
    Resources r = Resources.getSystem();
    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (visible) {
        CharSequence title;
        CharSequence details;
        int icon;
        Intent intent;
        Notification notification = new Notification();
        switch(networkType) {
            case ConnectivityManager.TYPE_WIFI:
                title = r.getString(R.string.wifi_available_sign_in, 0);
                details = r.getString(R.string.network_available_sign_in_detailed, extraInfo);
                icon = R.drawable.stat_notify_wifi_in_range;
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
                break;
            case ConnectivityManager.TYPE_MOBILE:
            case ConnectivityManager.TYPE_MOBILE_HIPRI:
                title = r.getString(R.string.network_available_sign_in, 0);
                // TODO: Change this to pull from NetworkInfo once a printable
                // name has been added to it
                details = mTelephonyManager.getNetworkOperatorName();
                icon = R.drawable.stat_notify_rssi_in_range;
                intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
                intent.putExtra("EXTRA_URL", url);
                intent.setFlags(0);
                notification.contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
                break;
            default:
                title = r.getString(R.string.network_available_sign_in, 0);
                details = r.getString(R.string.network_available_sign_in_detailed, extraInfo);
                icon = R.drawable.stat_notify_rssi_in_range;
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
                break;
        }
        notification.when = 0;
        notification.icon = icon;
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.tickerText = title;
        notification.setLatestEventInfo(mContext, title, details, notification.contentIntent);
        try {
            notificationManager.notify(NOTIFICATION_ID, 1, notification);
        } catch (NullPointerException npe) {
            loge("setNotificaitionVisible: visible notificationManager npe=" + npe);
            npe.printStackTrace();
        }
    } else {
        try {
            notificationManager.cancel(NOTIFICATION_ID, 1);
        } catch (NullPointerException npe) {
            loge("setNotificaitionVisible: cancel notificationManager npe=" + npe);
            npe.printStackTrace();
        }
    }
    mIsNotificationVisible = visible;
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Resources(android.content.res.Resources) Notification(android.app.Notification)

Example 12 with Notification

use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.

the class DeviceStorageMonitorService method sendNotification.

/**
    * This method sends a notification to NotificationManager to display
    * an error dialog indicating low disk space and launch the Installer
    * application
    */
private final void sendNotification() {
    if (localLOGV)
        Slog.i(TAG, "Sending low memory notification");
    //log the event to event log with the amount of free storage(in bytes) left on the device
    EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
    //  Pack up the values and broadcast them to everyone
    Intent lowMemIntent = new Intent(Environment.isExternalStorageEmulated() ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS : Intent.ACTION_MANAGE_PACKAGE_STORAGE);
    lowMemIntent.putExtra("memory", mFreeMem);
    lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationManager mNotificationMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence title = mContext.getText(com.android.internal.R.string.low_internal_storage_view_title);
    CharSequence details = mContext.getText(com.android.internal.R.string.low_internal_storage_view_text);
    PendingIntent intent = PendingIntent.getActivityAsUser(mContext, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
    Notification notification = new Notification();
    notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
    notification.tickerText = title;
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.setLatestEventInfo(getUiContext(), title, details, intent);
    mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
    mContext.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 13 with Notification

use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.

the class UiModeManagerService method adjustStatusBarCarModeLocked.

private void adjustStatusBarCarModeLocked() {
    if (mStatusBarManager == null) {
        mStatusBarManager = (StatusBarManager) mContext.getSystemService(Context.STATUS_BAR_SERVICE);
    }
    // have no effect until the device is unlocked.
    if (mStatusBarManager != null) {
        mStatusBarManager.disable(mCarModeEnabled ? StatusBarManager.DISABLE_NOTIFICATION_TICKER : StatusBarManager.DISABLE_NONE);
    }
    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    }
    if (mNotificationManager != null) {
        if (mCarModeEnabled) {
            Intent carModeOffIntent = new Intent(mContext, DisableCarModeActivity.class);
            Notification n = new Notification();
            n.icon = R.drawable.stat_notify_car_mode;
            n.defaults = Notification.DEFAULT_LIGHTS;
            n.flags = Notification.FLAG_ONGOING_EVENT;
            n.when = 0;
            n.setLatestEventInfo(getUiContext(), mContext.getString(R.string.car_mode_disable_notification_title), mContext.getString(R.string.car_mode_disable_notification_message), PendingIntent.getActivityAsUser(mContext, 0, carModeOffIntent, 0, null, UserHandle.CURRENT));
            mNotificationManager.notifyAsUser(null, R.string.car_mode_disable_notification_title, n, UserHandle.ALL);
        } else {
            mNotificationManager.cancelAsUser(null, R.string.car_mode_disable_notification_title, UserHandle.ALL);
        }
    }
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 14 with Notification

use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.

the class NotificationManagerService method updateLightsLocked.

// lock on mNotificationList
private void updateLightsLocked() {
    // handle notification lights
    if (mLedNotification == null) {
        // use most recent light with highest score
        for (int i = mLights.size(); i > 0; i--) {
            NotificationRecord r = mLights.get(i - 1);
            if (mLedNotification == null || r.sbn.getScore() > mLedNotification.sbn.getScore()) {
                mLedNotification = r;
            }
        }
    }
    // Don't flash while we are in a call, screen is on or we are in quiet hours with light dimmed
    if (mLedNotification == null || mInCall || (mScreenOn && !mDreaming) || (inQuietHours() && mQuietHoursDim)) {
        mNotificationLight.turnOff();
    } else {
        final Notification ledno = mLedNotification.sbn.getNotification();
        int ledARGB;
        int ledOnMS;
        int ledOffMS;
        NotificationLedValues ledValues = getLedValuesForNotification(mLedNotification);
        if (ledValues != null) {
            ledARGB = ledValues.color != 0 ? ledValues.color : mDefaultNotificationColor;
            ledOnMS = ledValues.onMS >= 0 ? ledValues.onMS : mDefaultNotificationLedOn;
            ledOffMS = ledValues.offMS >= 0 ? ledValues.offMS : mDefaultNotificationLedOff;
        } else {
            if ((mLedNotification.sbn.getNotification().defaults & Notification.DEFAULT_LIGHTS) != 0) {
                ledARGB = mDefaultNotificationColor;
                ledOnMS = mDefaultNotificationLedOn;
                ledOffMS = mDefaultNotificationLedOff;
            } else {
                ledARGB = mLedNotification.sbn.getNotification().ledARGB;
                ledOnMS = mLedNotification.sbn.getNotification().ledOnMS;
                ledOffMS = mLedNotification.sbn.getNotification().ledOffMS;
            }
        }
        if (mNotificationPulseEnabled) {
            // pulse repeatedly
            mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED, ledOnMS, ledOffMS);
        }
    }
}
Also used : Notification(android.app.Notification) ITransientNotification(android.app.ITransientNotification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 15 with Notification

use of android.app.Notification in project android_frameworks_base by ParanoidAndroid.

the class AccountManagerService method doNotification.

private void doNotification(UserAccounts accounts, Account account, CharSequence message, Intent intent, int userId) {
    long identityToken = clearCallingIdentity();
    try {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "doNotification: " + message + " intent:" + intent);
        }
        if (intent.getComponent() != null && GrantCredentialsPermissionActivity.class.getName().equals(intent.getComponent().getClassName())) {
            createNoCredentialsPermissionNotification(account, intent, userId);
        } else {
            final Integer notificationId = getSigninRequiredNotificationId(accounts, account);
            intent.addCategory(String.valueOf(notificationId));
            Notification n = new Notification(android.R.drawable.stat_sys_warning, null, 0);
            UserHandle user = new UserHandle(userId);
            final String notificationTitleFormat = mContext.getText(R.string.notification_title).toString();
            n.setLatestEventInfo(mContext, String.format(notificationTitleFormat, account.name), message, PendingIntent.getActivityAsUser(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, user));
            installNotification(notificationId, n, user);
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UserHandle(android.os.UserHandle) Notification(android.app.Notification)

Aggregations

Notification (android.app.Notification)552 PendingIntent (android.app.PendingIntent)265 Intent (android.content.Intent)240 NotificationManager (android.app.NotificationManager)122 StatusBarNotification (android.service.notification.StatusBarNotification)96 NotificationCompat (android.support.v4.app.NotificationCompat)58 Resources (android.content.res.Resources)55 Context (android.content.Context)47 Bitmap (android.graphics.Bitmap)47 Test (org.junit.Test)45 ITransientNotification (android.app.ITransientNotification)32 RemoteViews (android.widget.RemoteViews)30 RemoteException (android.os.RemoteException)24 UserHandle (android.os.UserHandle)17 Date (java.util.Date)16 Uri (android.net.Uri)15 Bundle (android.os.Bundle)13 File (java.io.File)13 ApplicationInfo (android.content.pm.ApplicationInfo)12 SuppressLint (android.annotation.SuppressLint)11