public class LocalReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent iii) {
//活动Activity(5秒)一般不要做超过5秒,广播BroadcastReceiver都是主线程(10秒),Service服务相当于子线程
//所以广播此处如果做耗时操作,一般会开启服务
// Intent intent2 = new Intent(context,MyService.class);
//在Activity里面所有直接写出来的方法,比如getSystemService(WINDOW_SERVICE),findViewById(),全部要加上context.getSystemService(Context.WINDOW_SERVICE)
// MainActivity ma = (MainActivity)context;
// Log.i("接收的数据:", intent.getStringExtra("args"));
// Toast.makeText(context, "接收本地广播", Toast.LENGTH_SHORT).show();
NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
//延迟Intent
Intent intent = new Intent(context,ShowActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);//PendingIntent.
RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.vedio);
rViews.setImageViewResource(R.id.iv, R.drawable.title);//修改图片(那个控件,什么内容)
rViews.setTextViewText(R.id.tv, "我改了我改了");//修改文字
// 通知的使用
// Builder builder = new Notification.Builder(context);
// Notification notification = builder.build();
Notification notification = new Notification.Builder(context)
.setContent(rViews)//设置自定义界面
.setContentIntent(pi)
.setContentText("内容")
.setTicker("提示标题")
.setSmallIcon(R.drawable.ic_launcher)//显示的小图标
.setWhen(new Date().getTime())
.setLights(Color.GREEN, 2000, 1000)
.setVibrate(new long[]{0,1000,1000,1000,1000,1000,1000,1000,1000})
.setNumber(100)//显示在右边的数字
// .setExtras(bag)//带数据
.build();
// notification.ledARGB = Color.GREEN;//一般是绿色,黄色,红色
// notification.ledOffMS = 1000;
// notification.ledOnMS = 1000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;//显示灯
//notification.flags = Notification.FLAG_AUTO_CANCEL;//点击这条消息后,自动取消
//通知管理器发送
manager.notify(1, notification);
}
}