1- Does the GPS bearing Bearing matter which way you hold the phone
Assuming "way" means "orientation" then:
No. The GPS bearing measurement (and speed measurement) is done using Doppler shift to detect differences of movement of the GPS receiver relative to the satellites, to calculate movement of the receiver relative to the earth's surface. Bearing is the direction of
movement of the receiver, not its orientation.
QUESTION 1 is there a way to get the direction of travel without worrying if the handset is in a bag held in a funny way (upside down ) or at an angle.
A GPS fix received via the LocationChanged event includes Bearing and Speed (and BearingValid and SpeedValid) of travel:
Ignore the "or sets" mention; the Location type is used for a variety of navigation-related calculations, not just for returning GPS readings.
I need to know if I am travelling down a river in a direction or up a river in the opposite direction so I need to know the bearing without worrying which way the device is held.
Today is your lucky day: it's like the designers of GPS saw you coming
Assuming you know the direction of the river that you are on, then: if the GPS bearing is within 90 degrees of this direction, you are heading down-river; otherwise, you are heading up-river.
QUESTION 2 Is there a library that can handle this in B4A, with this taken into consideration.
Again assuming you know the direction of the river you are on, then: no library required, a simple comparison with the GPS LocationChanged Bearing will do the job.
Determining the direction of the river at your current location is perhaps trickier. Rivers often have bends and loopbacks and diversions and forks where the river path wends left or right and can often end up being the opposite direction to the overall path of the river. I know that in OpenStreetMap data, a "way" (line segment) has direction, and I would be very surprised if the ways used to represent a river were not in the direction of river flow.
Another issue might be a tide-affected waterway, where the water alternately flows in both directions. And then there's canals, with nominally no water movement. I'd guess there that the direction would be taken as being towards locks to a lower water level. Actually, that could be a way of determining the direction of a river - use the river's elevations to work out which way is downhill. Although that opens up a new can of exceptions, like if you're a caver canoeing on an underground waterway. Or on a canal viaduct. But these are all bridges we can cross when we get to them.