在服务中有这个方法,可以绑定一个Notification,启动一个前置服务,就像金山软件那样,
void android.app.Service.startForeground(int id, Notification notification)
private void setUpAsForeground(String text,Class cls) {
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, new Intent(getApplicationContext(),
cls), PendingIntent.FLAG_UPDATE_CURRENT);
mNotification = new Notification();
mNotification.tickerText = text;
mNotification.icon = R.drawable.logo;// TODO 更换服务前置的图标
mNotification.flags = Notification.FLAG_ONGOING_EVENT;
mNotification.icon = R.drawable.logo;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification.setLatestEventInfo(getApplicationContext(), "", text,
pendingIntent);
startForeground(NOTIFICATION_ID, mNotification);
}
stopForeground(true);//停止一个前置服务
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, new Intent(getApplicationContext(),
cls), PendingIntent.FLAG_UPDATE_CURRENT);
mNotification = new Notification();
mNotification.tickerText = text;
mNotification.icon = R.drawable.logo;// TODO 更换服务前置的图标
mNotification.flags = Notification.FLAG_ONGOING_EVENT;
mNotification.icon = R.drawable.logo;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification.setLatestEventInfo(getApplicationContext(), "", text,
pendingIntent);
startForeground(NOTIFICATION_ID, mNotification);
}