1.尽量使用sdk中的android.support.v4(据说最新)
2.自定义通知栏样式
注意:
(1)最好是在Appliction中定义:onCreate() 中调用
(2)若要使用自定义通知栏样式,请勿重写方法dealWithNotificationMessage();否则,自定义通知栏样式将失效。
(3)dealWithCustomMessage是处理自定义消息的
3.如果要跳转到指定的页面,有以下2中方式
法1:需要在友盟平台上选择"打开指定页面",并填写包名.Activity类名
//不需要为自定义的状态栏通知的Notification传入Intent,即使设置了也无效
法2:需要在友盟平台上选择"打开指定页面",重写openActivity方法或者需要在友盟平台上选择"自定义行为",重写dealWithCustomAction方法
2.自定义通知栏样式
UmengMessageHandler messageHandler = new UmengMessageHandler(){
**
* 参考集成文档的1.6.4
* http://dev.umeng.com/push/android/integration#1_6_4
* */
@Override
public Notification getNotification(Context context,
UMessage msg) {
switch (msg.builder_id) {
case 1://显示样式编号,在友盟平台上控制
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
RemoteViews myNotificationView = new RemoteViews(context.getPackageName(), R.layout.notification_view);
myNotificationView.setTextViewText(R.id.notification_title, msg.title);
myNotificationView.setTextViewText(R.id.notification_text, msg.text);
// myNotificationView.setImageViewBitmap(R.id.notification_large_icon, getLargeIcon(context, msg));
// myNotificationView.setImageViewResource(R.id.notification_small_icon, getSmallIconId(context, msg));
builder.setContent(myNotificationView)
.setSmallIcon(getSmallIconId(context, msg))
.setTicker(msg.ticker)
.setAutoCancel(true);
return builder.build();
default:
//默认为0,若填写的builder_id并不存在,也使用默认。
return super.getNotification(context, msg);
}
}
};
mPushAgent.setMessageHandler(messageHandler);
注意:
(1)最好是在Appliction中定义:onCreate() 中调用
(2)若要使用自定义通知栏样式,请勿重写方法dealWithNotificationMessage();否则,自定义通知栏样式将失效。
(3)dealWithCustomMessage是处理自定义消息的
3.如果要跳转到指定的页面,有以下2中方式
法1:需要在友盟平台上选择"打开指定页面",并填写包名.Activity类名
//不需要为自定义的状态栏通知的Notification传入Intent,即使设置了也无效
法2:需要在友盟平台上选择"打开指定页面",重写openActivity方法或者需要在友盟平台上选择"自定义行为",重写dealWithCustomAction方法
/**
* 该Handler是在BroadcastReceiver中被调用,故
* 如果需启动Activity,需添加Intent.FLAG_ACTIVITY_NEW_TASK
* 参考集成文档的1.6.2
* http://dev.umeng.com/push/android/integration#1_6_2
* */
UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler(){
@Override
public void dealWithCustomAction(Context context, UMessage msg) {
//自定义行为
Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show();
Intent in = new Intent(context, TestActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
@Override
public void openActivity(Context context, UMessage msg) {
// TODO Auto-generated method stub
//super.openActivity(context, msg);//不可调用,否则无效
Toast.makeText(context, "测试跳转", Toast.LENGTH_LONG).show();
//跳转到指定页面
Intent in = new Intent(context, TestActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
};
//使用自定义的NotificationHandler,来结合友盟统计处理消息通知
//参考http://bbs.umeng.com/thread-11112-1-1.html
//CustomNotificationHandler notificationClickHandler = new CustomNotificationHandler();
mPushAgent.setNotificationClickHandler(notificationClickHandler);