NotificationCompa .Builder builder=new NotificationCompat.Builder(this):

RemotoViews remotoViews=new RemotoViews(getPackage(),R.layout.notifaton);

//5.0之后需要设置一张白色透明的smallIcon

if(android.os.Builder.VERSION.SDK_INT>=21){

builder.setSmallIcon(R.drawable.smallicon);

}else{

builder.setSmallIcon(R.mipmap.ic_launcher);

}

//下面两句设置的是不下拉状态栏节可以显示的信息

builder.setContentText(设置内容);

builder.setContentTiTle(标题);

//开始为下拉状态栏现实的view设置数据

remotoViews.setImageViewResource(R.id.img,R.mipmap.ic_launcher);

remotoViews.setTextViewText(R.id.tv,"内容");

//设置点击跳转页面

Intnet intent=new Intent(this,A.class);

PendingIntent pendingIntent=PendingIntent.getBroadCast(this,1,intent,PendingIntent.FLAG__ONE__SHOT);

bulder.setContent(remotoViews);

builder.setContentIntent(pendingIntnet);

//设置点击自动消失

builder.setAudoCancel(true);

//生成Notification

Notification notification=builder.builder();

//设置震动

notification.defaults|=Notification.DEFAULT_VIBRATE;

//设置提示音

notification.defaults|=Notification.DEFAULT_SOUND;

//给notification设置一个int值,方便以后删除

int i=(int)System.currentTimeMillis();

NotificationManager notificationManager=(NotificationManager)getSystemService(Content.NOTIFICATIN_SERVICE);

notificationManager.notify(i,notification);

results matching ""

    No results matching ""