notifications
How to send email from MySQL 5.1
If you have an SMTP service running, you can outfile to the drop directory. If you have high volume, you may result with duplicate file names, but there are ways to avoid that. Otherwise, you will need to create a UDF. Here’s a sample trigger solution: CREATE TRIGGER test.autosendfromdrop BEFORE INSERT ON test.emaildrop FOR EACH … Read more
How to add a notification badge/count to application icon on Sony Xperia devices?
After having seen Daniel Ochoa’s solution for Samsung’s launcher, which uses a BadgeProvider to handle the badges, I set out to do the same for Sony’s Xperia Home. This answer is taken directly from my blog. How I figured it out – For anyone interested I stumbled upon Sony’s AppXplore and used it to check … Read more
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
Notification click: activity already open
You need to set the launchMode attribute of the Activity you are starting to singleTop. This will cause incoming Intents to be delivered to the existing instance rather than starting a new instance when that Activity is already at the top of the task’s stack. This is done in the manifest by adding android:launchMode=”singleTop” to … Read more
Notification to restore a task rather than a specific activity?
What you need is just a simple Activity that does nothing. Here is an example: public class NotificationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Now finish, which will drop the user in to the activity that was at the top // of the task stack finish(); } } Set up … Read more
How to clear a notification in Android
Use the following code to cancel a Notification: NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); In this code there is alway the same id used for notifications. If you have different notifications that need to be canceled you have to save the ids that you used to create the Notification.
Create custom notification, android
Add RemoteViews in notification. Here is a sample: var remoteViews = new RemoteViews(getPackageName(), R.layout.widget); var mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContent(remoteViews); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, test.class); // The stack builder object will contain an artificial back stack for // the started Activity. // … Read more
How exactly to use Notification.Builder
Notification.Builder API 11 or NotificationCompat.Builder API 1 This is a usage example. Intent notificationIntent = new Intent(ctx, YourClass.class); PendingIntent contentIntent = PendingIntent.getActivity(ctx, YOUR_PI_REQ_CODE, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager nm = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); Resources res = ctx.getResources(); Notification.Builder builder = new Notification.Builder(ctx); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.some_img) .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img)) .setTicker(res.getString(R.string.your_ticker)) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle(res.getString(R.string.your_notif_title)) .setContentText(res.getString(R.string.your_notif_text)); Notification n = builder.build(); nm.notify(YOUR_NOTIF_ID, n);
Detect a new Android notification
Actually, it is possible, I use it in my app. For Android 4.2 and below: You need to register an AccessibilityService and make sure the user enables the service. Example for a service: public class InstantMessenger extends AccessibilityService { @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { //Do something, eg getting packagename … Read more