Some people say that animals cannot think. That is their nature. But when you study Surah al-Namal (27) about the conversation of the Prophet Solomon (sws) with Hud Hud about Bilquees, the polytheist queen, and about the conversations of ants you would definitely think that animals have ability to think and pray and know about Allah.
The word "thinking" has a definition that can be different for individuals. Animals do many things that we may call "thinking", like a dog that finds a way to rescue his owner. This "thinking" however is nothing close to the thinking ability of human being.
The Qur'an has informed us that ants warned each other about the army of Solomon stepping on them. There is nothing here against the facts we know about the worlds of ants (considering that when the Qur'an uses the word قالت (said) it does not necessarily mean oral communication).
Also Hud Hud simply communicated his observation with Solomon. This much of "thinking" is fully in line with our knowledge of animals' world.
In the case of Hud Hud however there can be another point to consider as well. As we know God has made some of his creatures to serve Solomon, it is likely that He gave those creatures (who were serving Solomon) abilities that otherwise they might not have had.
As for animals being aware of God and praying to Him, this is a fact that the Qur'an has actually referred to very explicitly (like Hud Hud in the verse 27:24, also look at 24:41, 16:49). In fact according to the Qur'an anything in the heaven and earth, even things that are not alive are aware of God and praise Him (62:1).