Monday, February 28, 2011

Android notification

Notification In Android
Download SourceCode

   Android notification four types there.
        1.Status Bar Notification.
        2.Sound
        3.viberate
        4.Flash light


Screen Shot









Source Code


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NotifiActivity extends Activity {
   
    private NotificationManager mNotificationManager;
    private int SIMPLE_NOTFICATION_ID;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        final Notification notifyDetails = new Notification(R.drawable.icon,"New Alert, Click Me!",System.currentTimeMillis());
       

        Button start = (Button)findViewById(R.id.Button01);
        Button cancel = (Button)findViewById(R.id.Button02);
       
        start.setOnClickListener(new OnClickListener() {
           
            public void onClick(View v) {
               
               
                Context context = getApplicationContext();
                CharSequence contentTitle = "Notification Details...";
                CharSequence contentText = "Browse Android Official Site by clicking me";
                Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
                PendingIntent intent =
                    PendingIntent.getActivity(NotifiActivity.this, 0,
                    notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
                /*notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);*/
                notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
                mNotificationManager.notify(0, notifyDetails);
            }
        });
       
        cancel.setOnClickListener(new OnClickListener() {
           
            public void onClick(View v) {
               
                mNotificationManager.cancel(0);
            }
        });
    }
}







Check out this may be help you

Related Posts Plugin for WordPress, Blogger...