Cocoa – Notification on NSUserDefaults value change?

Spent all day looking for the answer, only to find it 10 minutes after asking the question… Came across a solution through Key-Value-Observing: [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@”values.MyPreference” options:NSKeyValueObservingOptionNew context:NULL]; Or, more simply (per comment below): [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@”MyPreference” options:NSKeyValueObservingOptionNew context:NULL];

Can NoticationManager.notify() be called from a worker thread?

It is acceptable to update a Notification from a worker thread because the Notification does not live in your application’s process and hence you are not updating its UI directly. The Notification is maintained in a system process, and the Notification‘s UI is updated through RemoteViews (doc), which allows the manipulation of a view hierarchy … Read more

Is it possible to check if a notification is visible or canceled?

If you’re app has a minimum API >= 23 can use this method to get active notification: NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); StatusBarNotification[] notifications = mNotificationManager.getActiveNotifications(); for (StatusBarNotification notification : notifications) { if (notification.getId() == 100) { // Do something. } }

Local Notifications in Android?

Use NotificationCompat.Builder if you are targeting old APIs too. Intent intent = new Intent(ctx, HomeActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder(ctx); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_launcher) .setTicker(“Hearty365”) .setContentTitle(“Default notification”) .setContentText(“Lorem ipsum dolor sit amet, consectetur adipiscing elit.”) .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND) .setContentIntent(contentIntent) .setContentInfo(“Info”); NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, b.build());

Notification multiline

Add this : NotificationCompat.Builder builder = new NotificationCompat.Builder( context); Notification notification = builder.setContentIntent(contentIntent) .setSmallIcon(icon).setTicker(appname).setWhen(0) .setAutoCancel(true).setContentTitle(appname) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentText(message).build(); notificationManager.notify(0, notification); Also check : Multiline Notification

How to create a notification with NotificationCompat.Builder?

The NotificationCompat.Builder is the most easy way to create Notifications on all Android versions. You can even use features that are available with Android 4.1. If your app runs on devices with Android >=4.1 the new features will be used, if run on Android <4.1 the notification will be an simple old notification. To create … Read more

Android – Build a notification, TaskStackBuilder.addParentStack not working

You need to add the parent stack for the activity you’re launching, not the parent of it. Replace: stackBuilder.addParentStack(MainActivity.class); with: stackBuilder.addParentStack( MatchActivity.class ); This assumes that you’ve defined the parent in your Manifest (API 16+): <activity android:name=”.MatchActivity” android:parentActivityName=”.MainActivity” … /> If you’re developing for under API 16, then you have to define the parent as: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)