FileDocCategorySizeDatePackage
IncomingMessage.javaAPI DocGoogle Android v1.5 Example3402Sun Nov 11 13:01:04 GMT 2007com.google.android.samples.app

IncomingMessage

public class IncomingMessage extends android.app.Activity

Fields Summary
Constructors Summary
Methods Summary
private android.view.ViewinflateView(int resource)

        ViewInflate vi = (ViewInflate)getSystemService(Context.INFLATE_SERVICE);
        return vi.inflate(resource, null, null);
    
protected voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        setContentView(R.layout.incoming_message);

        Button button = (Button) findViewById(R.id.notify);
        button.setOnClickListener(new Button.OnClickListener() {
                public void onClick(View v) {
                    performNotification();
                }
            });
    
protected voidperformNotification()

        /*
         * Here we send a notification that is both transient and persistent.
         * The transient part is the view that comes up and shows the user
         * the text of what could be an incoming message.  The persistent part
         * goes into the status bar where they can acknowledge it later.
         */

        // look up the notification manager service
        NotificationManager nm = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);


        // the transient notification =======================================
        
        // create the view
        View view = inflateView(R.layout.incoming_message_panel);

        // set the text in the view
        TextView tv = (TextView)view.findViewById(R.id.message);
        tv.setText("kthx. meet u for dinner. cul8r");


        // the persistent notification ======================================

        // what happens when we click the icon
        Intent clickIntent = new Intent(Intent.MAIN_ACTION);
        clickIntent.setClass(this, IncomingMessageView.class);

        // construct the Notification object.
        Notification notif = new Notification(
                            R.drawable.stat_sample,
                            getText(R.string.status_bar_notification_title),
                            clickIntent, null, null);

        // after a 100ms delay, vibrate for 250ms, pause for 100 ms and
        // then vibrate for 500ms.
        notif.vibrate = new long[] { 100, 250, 100, 500};


        // send the notification ============================================

        nm.notifyWithView(R.layout.incoming_message_panel, view,
                NotificationManager.LENGTH_LONG, notif);