chechunli@chechunli-PC:notification $ cat src/com/android/test/notification.java
package com.android.test;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
public class notification extends Activity
{
private Button mButton1;
private TextView mTextView1;
/* init ptr */
private NotificationManager myNotiManager;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myNotiManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mButton1 = (Button) findViewById(R.id.myButton1);
mTextView1 = (TextView) findViewById(R.id.myTextView1);
mButton1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
setNotiType(R.drawable.offine,"ok");
}
});
}
/* send Notification method */
private void setNotiType(int iconId, String text)
{
/* set a intent to go to the Activity when point the notification */
Intent notifyIntent=new Intent(this,point_notify.class);
notifyIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
/* set PendingIntent delay Activity */
PendingIntent appIntent=PendingIntent.getActivity(notification.this,0,
notifyIntent,0);
/* start a Notication, set ptr */
Notification myNoti=new Notification();
/* set statusbar icon */
myNoti.icon=iconId;
/* set statusbar text */
myNoti.tickerText=text;
/* set notification sound when action */
myNoti.defaults=Notification.DEFAULT_SOUND;
/* set Notification leaving message ptr */
myNoti.setLatestEventInfo(notification.this,"status",text,appIntent);
/* send Notification */
myNotiManager.notify(0,myNoti);
}
}
chechunli@chechunli-PC:notification $ cat src/com/android/test/point_notify.java
package com.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class point_notify extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Toast.makeText(point_notify.this, "point Activity", Toast.LENGTH_SHORT ).show();
finish();
}
}