package cn.itcast.customnoti;
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.widget.RemoteViews;
public class CustomNotificationActivity extends Activity {
/** Called when the activity is first created. */
NotificationManager notificationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
public void click(View view ){
// 1. 获取到系统的notificationManager
// 2. 实例化一个notification
String tickerText = "IP号码 设置完毕";
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.icon, tickerText, when);
// notification.flags= Notification.FLAG_NO_CLEAR
// notification.sound = Uri.parse("/sdcard/haha.mp3");
//3 .设置用户点击notification的动作
// pendingIntent 延期的意图
Intent intent = new Intent(this,Bactivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
//RemoteView
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.noti_layout);
rv.setTextViewText(R.id.tv_rv, "我是自定义的 notification");
rv.setProgressBar(R.id.pb_rv, 100, 20, false);
notification.contentView = rv;
notification.contentIntent = pendingIntent;
//4. 把定义的notification 传递给 notificationmanager
notificationManager.notify(0, notification);
}
}