Showing posts with label notification. Show all posts
Showing posts with label notification. Show all posts

Thursday, March 20, 2014

Android Tip - Displaying Notifications

In Android, a good way to notify the user outside of your application is through posting a notification in the notification area of the device. The notification will appear until the user opens the notification drawer and taps on it. Usually, tapping the notification will launch the application that displays the notification.

To create a notification, use the NotificationCompat.Builder class to create a Notification object, as shown in the following method:

    private void postNotification(String title, String msg) {
        //---which activity should be launched when the
        // notification is tapped---        
        Intent resultIntent = new Intent(this,
            MainActivity.class);
        PendingIntent pendingIntent =
                PendingIntent.getActivity(
                this,
                0,
                resultIntent,
                PendingIntent.FLAG_UPDATE_CURRENT
            );       
       
        //---create a notification---
        Notification notification = new
            NotificationCompat.Builder(this)   
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentText(msg)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .setNumber(1)
            .build();
       
        //---set the sound and lights---
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
       
        //---display the notification---
        notificationManager.notify(
            NOTIFICATION_ID,
            notification);       
    }

Each notification is identified using a notification id. Posting another notification using the same id replaces the previous notifications. You also need to use the NotificationManager class to post the notification:

public class MainActivity extends Activity { 
    private static final int NOTIFICATION_ID = 123;
    NotificationManager notificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        notificationManager = (NotificationManager)
            getSystemService(
                Context.NOTIFICATION_SERVICE);
    }

You can now post a notification by calling the method that you have just defined:

        postNotification(
            "A sample notification",
            "Just testing the notification...");  


Thursday, January 09, 2014

WEB102 – 1-Day Developing HTML5 Web Applications - NEW COURSE

HTML 5 is the new standard for the venerable HTML specification, a standard for displaying Web content. HTML has come a long way, going through a number of revisions - with the last version - 4.01, recommended by the W3C in 1999. The design goal of HTML 5 is to ensure that an application that you write can work on all browsers without the need to install additional plug-ins. It should be able to do everything from animation, to music and videos, local storage, offline applications, and more. HTML 5 is also cross platforms, meaning that your apps should be able to work whether it is run on a notebook, smartphone, tablet, or desktop computer.

In this 1-day course, you will be able to understand and use the new features of HTML5 through working with practical examples.

Topics

•          Quick Introduction to HTML
•          Crash Course in JavaScript and CSS
•          Using Canvas for drawing graphics    
•          Using SVG (Scalable Vector Graphics) in your HTML 5 pages
•          Implementing drag-and-drop in your Web Pages
•          Implementing LBS (Location-Based Services) in your Web applications
•          Embedding audios and videos in your Web pages
•          Using different input types in your Web pages
•          Using Web storage in HTML 5
•          Creating offline Web applications
•          Creating responsive Web applications using Web Worker

•          Implementing notifications in your Web applications through server messaging

Venue
Bayview Hotel Singapore
30 Bencoolen Street 
Singapore 189621

9am to 5pm

Fee
S$699 (nett)

Dates
21 Feb 2014 (Fri)

Download course outline and application form here.