Wen, I agree with you on Midnight Cowboy; there was a pretty strong indication of a gay relationship.
As for your main question, I don't know any way to be sure of characters' sexual orientation in books or movies. Hollywood in particular often makes characters rather nebulous, and does so purposely I think.
I also think you can't be certain in many real life situations. I have a number of really close friends who wouldn't think twice about about hugging each other in public. A casual observer, especially a gay person, could easily jump to the wrong conclusion. My friends, especially college fraternity brothers, are a close knit group. Occasionally; I will see one I haven't seen in 45 years; we will certainly hug each other. This sort of greeting is becoming more important as we are losing more friends each year. You never know when the next funeral will be. To my knowledge, none of these friends is gay. At this point, I doubt that would matter.