Lao is correct that it is often used jokingly so it wouldn't be used with people to whom you should show respect or with people you don't know well; there must first be a level of comfort and familiarity, but it also can be used to show empathy. It is usually your manner which says the difference.
It can mean, "I'm glad I'm not you," or "I don't envy what you have to do or are about to face."
Examples:
Say one teenager is telling his friend about having to go to a family reunion where it will be mostly older people talking about how life changes and saying the same things to different people and you can tell it is something he/she doesn't want to do (as well as something you wouldn't enjoy either), then you would say it either as a joke or to show understanding depending on the type of friend.
Perhaps Monday morning you walk in to work and find out the boss wants to see you, and that's not usually a positive thing at the company, your competitive co-worker may then say it with a smile,
If you are in university and you are telling your classmate that you have two exams on the same day. That classmate may know how terrible that situation is and say it then actually meaning, 'I understand how bad that is.