您的位置:首页 > 其它

Notifiation通知的一些知识

2015-07-07 19:38 330 查看
通知,即push消息,需要添加icon、defaults、flags;

下面是一些知识点:是通过开启一个定时器,循环判断是否是桌面,是桌面则发送push信息,点击 push,响应一个INTENT_ACTION_VIEW,发送一个url链接到浏览器:

/**

* 开始定时器

*/

private void startTimer() {

if (mTimer == null) {

mTimer = new Timer();

CheckTask lockTask = new CheckTask();

mTimer.schedule(lockTask, 0L, 1000L);

}

}

/**

* 关闭监听服务

*/

public void closeTimer() {

if (mTimer != null) {

mTimer.cancel();

mTimer = null;

}

}

/**

* 定时器执行任务

*/

public class CheckTask extends TimerTask {

@Override

public void run() {

if (PackageMangerTool.isLauncherRunnig(MainActivity.this)) {

Intent it = new Intent("action.after.out");

showNotifation(getApplicationContext(), title, pic, it);

closeTimer();

MainActivity.this.finish();

}

}

}

@SuppressWarnings("deprecation")

private void showNotifation(Context mContext, String title, String pic,

Intent it) {

//获取NotificationManager

NotificationManager manager = SystemServiceUtils

.getNotificationManager(mContext);

Notification notification = new Notification();

notification.icon = android.R.drawable.ic_dialog_info;// 默认图标

notification.defaults |= Notification.DEFAULT_ALL;// 使用默认闪光提示

notification.flags |= Notification.FLAG_AUTO_CANCEL; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用

//notification.tickerText = "wwq";// 设置标题

notification.flags |= Notification.FLAG_NO_CLEAR;// 不可清除

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse(url));

// 获得PendingIntent

PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);

notification.setLatestEventInfo(this,push的title,

push的内容, pi);

manager.notify(1, notification);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: