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

NotifyWithText.java

/* 
 * Copyright (C) 2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.samples.app;

import com.google.android.samples.R;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.Notification;
import android.widget.Button;
import android.os.Bundle;
import android.view.View;

/**
 * When you push the button on this Activity, it schedules a notification
 * using the notifyWithText method.
 * @see NotificationManager#notifyWithText(int,CharSequence,int,Notification);
 * @see NotificationManager#LENGTH_SHORT
 * @see NotificationManager#LENGTH_LONG
 */
public class NotifyWithText extends Activity {
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.notify_with_text);

        Button button;

        // short notification
        button = (Button) findViewById(R.id.short_notify);
        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Get the notification manager serivce.
                NotificationManager nm = (NotificationManager)
                        getSystemService(NOTIFICATION_SERVICE);

                // The id we use here happens to be the id of the text we
                // display.  You can use any int here that is unique within
                // your application.
                nm.notifyWithText(R.id.short_notify,
                        getText(R.string.short_notification_text),
                        NotificationManager.LENGTH_SHORT, null);
            }
        });

        // long notification
        // The only difference here is that the notification stays up longer.
        // You might want to use this if there is more text that they're going
        // to read, like an email subject or something.
        button = (Button) findViewById(R.id.long_notify);
        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                NotificationManager nm = (NotificationManager)
                        getSystemService(NOTIFICATION_SERVICE);
                nm.notifyWithText(R.id.long_notify,
                        getText(R.string.long_notification_text),
                        NotificationManager.LENGTH_LONG, null);
            }
        });





    }
}