else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Logger.d("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
processCustomMessage(context, bundle);
Log.v("Lgqq","接收到推送下来的自定义消息");
MyJPushReceiver e=new MyJPushReceiver();
//需要调用的时候先注册,传入Boss类型对象和员工参数
MyJPushReceiver e1=e.zhuce(new OneActivity(), e);
int mynum = ShareUtil.getSharedInt("num");
mynum++;
ShareUtil.sharedPint(""+mynum,num);
// e1.dosomething(bundle.getString(JPushInterface.EXTRA_MESSAGE));
//通知开始
RemoteViews customView = new RemoteViews(context.getPackageName(), R.layout.kongreveiver);
customView.setTextViewText(R.id.neirongte,bundle.getString(JPushInterface.EXTRA_MESSAGE));
String name = bundle.getString(JPushInterface.EXTRA_MESSAGE);
customView.setTextViewText(R.id.pname,"圆心部落测试消息");
Intent companyIntroduce = new Intent(context, TwoAcitvity.class);
companyIntroduce.putExtra("name", name);
int notifyId = (int) System.currentTimeMillis();
PendingIntent pendingIntent = PendingIntent.getActivity(context, notifyId, companyIntroduce, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder
// .setContentText(bundle.getString(JPushInterface.EXTRA_MESSAGE)) //设置通知栏显示内容setContent、setContentText二选一
.setContent(customView)
.setContentIntent(pendingIntent) //设置通知栏点击意图
// .setNumber(mynum) //设置通知集合的数量
.setTicker(context.getPackageName() + "测试消息")//通知首次出现在通知栏,带上升动画效果的setTicker、setTextViewText二选一
.setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间。使用setContent,只能到customView显示
.setPriority(Notification.PRIORITY_DEFAULT) //设置该通知优先级
.setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消
.setDefaults(Notification.DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单DEFAULT_ALL是声音与震动,DEFAULT_SOUND声音
.setSmallIcon(R.mipmap.ic_launcher);
mNotificationManager.notify(notifyId, mBuilder.build());//发出通知
}
kongreveiver.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:background="@color/white" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:padding="5dp" android:weightSum="6"> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginLeft="11dp" android:layout_weight="5" android:gravity="center_vertical" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/zan_icon"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="就是你" android:textColor="@color/colorPrimary"/> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="名字" android:textColor="@color/colorPrimary" android:textSize="15dp" android:id="@+id/pname"/> <TextView android:id="@+id/neirongte" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:text="neir" android:textColor="@color/colorPrimary" android:textSize="14dp"/> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="right"> <ImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginRight="12dp" android:src="@mipmap/ic_launcher"/> </LinearLayout> </LinearLayout> </LinearLayout>