java代码如下:
package org.lxh.demo;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Hello extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // 生命周期方法
super.setContentView(R.layout.main); // 设置要使用的布局管理器
NotificationManager notificationManager = (NotificationManager) super
.getSystemService(Activity.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.pic_m, "您有新消息",
System.currentTimeMillis());// 实例化对象
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
super.getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);// 创建一个PendingIntent对象
notification.setLatestEventInfo(this, "新消息", "通知测试,谢谢", contentIntent);
notificationManager.notify("notice", R.drawable.pic_m, notification);
}
}