[Android] PendingIntent achieve sends a notification (notification)

java code as follows:

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);
 
	}
}

Here Insert Picture Description

Published 73 original articles · won praise 17 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_40110781/article/details/104956378