显示通知
private void processCustomMessage(Context context, Bundle bundle) { RemoteViews customView = new RemoteViews(context.getPackageName(), R.layout.kongreveiver); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); int ifnotifica = ShareUtil.getSharedInt("ifnotifica"); // if (ifnotifica==0){ // thread.join(); // } // if (timemin==0){ // mBuilder .setDefaults(Notification.DEFAULT_ALL); // waittime = 60000; // customView.setTextViewText(R.id.timemy,"刚刚"); // }else { // customView.setTextViewText(R.id.timemy,timemin+"分钟前"); // } String time = getTime(); // String hhmm = timetodate(time); customView.setTextViewText(R.id.timemy,time); customView.setTextViewText(R.id.name,bundle.getString(JPushInterface.EXTRA_TITLE)); customView.setTextViewText(R.id.neirongte,bundle.getString(JPushInterface.EXTRA_MESSAGE)); Intent intentCancel = new Intent(context,NotificationBroadcastReceiver.class); PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(context,0, intentCancel,PendingIntent.FLAG_ONE_SHOT); String ss =ShareUtil.getSharedString("jpushstring"); // if (TextUtil.isEmpty(ss)){ // ShareUtil.sharedPstring("jpushstring",onestring); // }else { // String endstring = ss+","+onestring; // // ShareUtil.sharedPstring("jpushstring",endstring); // // } Intent companyIntroduce = new Intent(context, TestpictureActivity.class); companyIntroduce.putExtra("tz",bundle.getString(JPushInterface.EXTRA_MESSAGE)); // companyIntroduce.putExtra("name", name); int notifyId = (int) System.currentTimeMillis(); PendingIntent pendingIntent = PendingIntent.getActivity(context, notifyId, companyIntroduce, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder//设置通知栏标题 // .setContentText(bundle.getString(JPushInterface.EXTRA_MESSAGE)) //设置通知栏显示内容 .setContent(customView) .setContentIntent(pendingIntent) //设置通知栏点击意图 .setDeleteIntent(pendingIntentCancel)//取消消息回调 // .setTicker(context.getPackageName() + "消息")//通知首次出现在通知栏,带上升动画效果的 .setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间 .setPriority(Notification.PRIORITY_DEFAULT) //设置该通知优先级 .setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消 //.setOngoing(false)//ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) // .setDefaults(Notification.DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合 // .setDefaults(Notification.DEFAULT_SOUND) //Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE permission .setSmallIcon(R.mipmap.ic_launcher); // mNotificationManager.notify(notifyId, notify); Log.i("lgqq","body=====id============"+tzid); int num = ShareUtil.getSharedInt("num"); num++; ShareUtil.sharedPint("num",num); mNotificationManager.notify(num, mBuilder.build()); }
接收通知消息Activity
public class TestpictureActivity extends Activity { private int yellowColor = Color.argb(255, 253, 197, 53); private int greenColor = Color.argb(255, 27, 147, 76); private int redColor = Color.argb(255, 211, 57, 53); private int blueColor = Color.argb(255, 76, 139, 245); PieChartView pieChartView; RadarChartView radarChartView; LineChartView lineChartView; LBarChartView LBarChartView; LinearLayout linearLayout; TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.picturela); pieChartView = (PieChartView) findViewById(R.id.pieView); radarChartView = (RadarChartView) findViewById(R.id.radarView); lineChartView = (LineChartView) findViewById(R.id.lineView); LBarChartView = (LBarChartView) findViewById(R.id.frameNewBase); linearLayout = (LinearLayout) findViewById(R.id.dli); textView = (TextView) findViewById(R.id.mytztextte); String ss = getIntent().getStringExtra("tz"); textView.setText(ss);