Search in sources :

Example 36 with NotificationManager

use of android.app.NotificationManager in project leakcanary by square.

the class LeakCanaryInternals method showNotification.

public static void showNotification(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent pendingIntent, int notificationId) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification;
    Notification.Builder builder = //
    new Notification.Builder(context).setSmallIcon(R.drawable.leak_canary_notification).setWhen(System.currentTimeMillis()).setContentTitle(contentTitle).setContentText(contentText).setAutoCancel(true).setContentIntent(pendingIntent);
    if (SDK_INT < JELLY_BEAN) {
        notification = builder.getNotification();
    } else {
        notification = builder.build();
    }
    notificationManager.notify(notificationId, notification);
}
Also used : NotificationManager(android.app.NotificationManager) Notification(android.app.Notification)

Example 37 with NotificationManager

use of android.app.NotificationManager in project NotificationPeekPort by lzanita09.

the class MainActivity method sendTestNotification.

/**
     * Lock device screen and send test notification.
     */
private void sendTestNotification() {
    final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    Handler handler = new Handler(getMainLooper());
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    final Notification.Builder builder = new Notification.Builder(this);
    builder.setSmallIcon(R.drawable.ic_launcher).setTicker(getString(R.string.diagnosis_notification_title)).setContentTitle(getString(R.string.diagnosis_notification_title_content)).setContentText(getString(R.string.diagnosis_notification_content)).setLights(Color.GREEN, 1000, 5000).setAutoCancel(true).setContentIntent(pendingIntent);
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            devicePolicyManager.lockNow();
        }
    }, LOCK_SCREEN_DELAY);
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            manager.notify(TEST_ID, builder.build());
            finish();
        }
    }, SEND_NOTIFICATION_DELAY);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 38 with NotificationManager

use of android.app.NotificationManager in project AndroidDevMetrics by frogermcs.

the class AndroidDevMetrics method showNotification.

private void showNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_timeline_white_18dp).setContentTitle(context.getString(R.string.adm_name)).setContentText("Click to see current metrics").setAutoCancel(autoCancelNotification);
    Intent resultIntent = new Intent(context, MetricsActivity.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify("AndroidDevMetrics".hashCode(), mBuilder.build());
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 39 with NotificationManager

use of android.app.NotificationManager in project benCoding.AlarmManager by benbahrenburg.

the class AlarmManagerProxy method cancelNotification.

@Kroll.method
public void cancelNotification(int requestCode) {
    NotificationManager notificationManager = (NotificationManager) TiApplication.getInstance().getSystemService(TiApplication.NOTIFICATION_SERVICE);
    notificationManager.cancel(requestCode);
}
Also used : NotificationManager(android.app.NotificationManager)

Example 40 with NotificationManager

use of android.app.NotificationManager in project coursera-android by aporter.

the class NotificationStatusBarWithCustomViewActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mNotificationIntent = new Intent(getApplicationContext(), NotificationSubActivity.class);
    mContentIntent = PendingIntent.getActivity(getApplicationContext(), 0, mNotificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Define the Notification's expanded message and Intent:
            mContentView.setTextViewText(R.id.text, contentText + " (" + ++mNotificationCount + ")");
            // Build the Notification
            Notification.Builder notificationBuilder = new Notification.Builder(getApplicationContext()).setTicker(tickerText).setSmallIcon(android.R.drawable.stat_sys_warning).setAutoCancel(true).setContentIntent(mContentIntent).setSound(soundURI).setVibrate(mVibratePattern).setContent(mContentView);
            // Pass the Notification to the NotificationManager:
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
        }
    });
}
Also used : NotificationManager(android.app.NotificationManager) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) View(android.view.View)

Aggregations

NotificationManager (android.app.NotificationManager)407 Intent (android.content.Intent)206 PendingIntent (android.app.PendingIntent)200 Notification (android.app.Notification)153 NotificationCompat (android.support.v4.app.NotificationCompat)116 Context (android.content.Context)31 Uri (android.net.Uri)26 Bitmap (android.graphics.Bitmap)24 Resources (android.content.res.Resources)22 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)20 Bundle (android.os.Bundle)19 TaskStackBuilder (android.app.TaskStackBuilder)15 StatusBarNotification (android.service.notification.StatusBarNotification)15 Random (java.util.Random)15 SharedPreferences (android.content.SharedPreferences)13 BitmapFactory (android.graphics.BitmapFactory)13 IntentFilter (android.content.IntentFilter)12 ComponentName (android.content.ComponentName)10 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9