To detect "unconnected" in a good way you need a hardware change, but in this case it would be better to add the pull-up instead.
I think the best solution depends on the project. How many boards do you build? Is it for a commercial product that you will sell?
If the number of boards is small, maybe you can add a pull-up as a hardware fix?
If you really need to solve it without a hardware change, you could try to activate the output driver on the pin with short pulses of the "inactive" level. Because of capacitance etc the level will change slowly if the pin is not driven. This means that you can sample the input a certain time after a pulse. If it isn't driven, you will see the inactive level.
If the input is driven active, you will have contention during the pulses. Use the weakest possible driver for the pulses. This is an "ugly" solution which can't be used for all projects.