Oil giant BP has posted a higher-than-expected profit of more than £4.2 billion for the first half of 2024 and hiked its dividend for shareholders.