All Mitzvos require Kavana in order to fulfill the obligation. This means that one must have in mind when fulfilling the action of the Mitzvah that he is doing so for the sake of fulfilling G-d’s command. Thus before blowing Shofar or hearing the blows one must have in mind to fulfill the Mitzvah of hearing Shofar. [This applies equally to the second day of Rosh Hashanah as even Rabbinical commands require intent.]
Must the blower and listener both have intent? Both the blower and listener must have in mind to fulfill the Mitzvah in order for the listener to fulfill his obligation. It does not suffice for the blower to have in mind to fulfill his personal Mitzvah and he must also have in mind to fulfill the Mitzvah for the listener. However it is not necessary for the blower to have in mind the identity of the listener and rather it suffices for him to have intent to include in the Mitzvah whoever desires to hear it and fulfill their obligation. Thus anyone who hears the blowing of the Minyan fulfills his obligation even if he is hearing it while walking outside the Shul or while in his house, so long as he intends to fulfill his Mitzvah. [It is proper for the Baal Tokeia to quietly verbalize prior to the blessings that he has in mind with the blessings and the blows to fulfill the obligation of all the listeners.]
If one is unsure if he had intent: If one heard the blow of the Shofar and afterwards entered into doubt if he had intent to fulfill the Mitzvah with hearing that blowing, he is required to hear Shofar a second time due to doubt. If however one was walking and he stopped in order to hear the Shofar blowing from the Shul and afterwards entered into doubt as to whether he had intent to fulfill his obligation with this hearing, he is not required to rehear the blowing.
If one came to Shul to hear Shofar must he have specific intent prior to the blowing? If one came to Shul in order to hear the Shofar blowing and fulfill the Mitzvah together with the congregation then he fulfills his obligation even if at the time of the blowing he did not have explicit intent to fulfill the Mitzvah and rather heard it without any intent. If however he came to Shul without any specific intent, and hence did not come in order to fulfill his obligation of hearing the Shofar from the Chazan, then if he did not intend during the blowing to fulfill the Mitzvah he has not fulfilled his obligation.
If one only began having intent in middle of the blowing: If one only began having intent to fulfill the Mitzvah within the midst of a specific blow, then that blow is invalid even if it contained the minimum required sound from when he began intending. [Thus if he came in middle of the first Tekiah of a set he must hear that entire set again being the first Tekiah is invalid.]
Practically if one did not have explicit intent to fulfill the Mitzvah does he fulfill his obligation?
Some Poskim rule that one is only required to repeat a Mitzvah if he did not have explicit intent if it is possible that he intended on doing the action of the Mitzvah for other purposes. If however it is clearly evident that he did the action for the sake of the Mitzvah then he fulfills his obligation even if he did not have explicit intent. Nevertheless initially one is to have explicit intent before the Mitzvah.
 If one does not have this intent then he does not fulfill his obligation as explained in 60/5. [ibid; There Admur brings a dispute regarding whether Mitzvos require intent and he rules like the stringent opinion.] Therefore one who is blowing Shofar for the sake of practice, or one who hears Shofar from one who is blowing for practice, does not fulfill his obligation. This applies even if the listener had in mind to fulfill his obligation, nevertheless since the blower did not have this intent he has heard an invalid blow. [ibid] Similarly if one blew for the sake of song and did not have intent to fulfill the Mitzvah has not fulfilled his obligation. Likewise one who heard the blowing from this individual does not fulfill his obligation. [589/6]
 See 60/5 and 475/29 in which Admur brings a dispute in whether Rabbinical commands require intent. Practically he rules that even Rabbinical Mitzvos require intent and if one did the Mitzvah without intent it is proper to repeat the Mitzvah.
 If the person blowing had in mind to fulfill the Mitzvah although the listener did not have in mind to fulfill his Mitzvah with this blowing then the listener has not fulfilled his obligation. If the listener had in mind to fulfill the Mitzvah although the blower did not have to fulfill the Mitzvah for the listener, then the listener must hear Shofar a second time even if the blower had in mind to fulfill his personal obligation. [ibid]
 Thus one who blows Shofar and has intent to fulfill the obligation of whoever desires to listen to his blow, anyone who heard the blow and intended to fulfill their obligation has fulfilled the Mitzvah, even though the blower did not intend on this specific person that heard his blow and he does not know of him at all. [ibid]
 The reason for this is because the Shliach Tzibur which is blowing the Shofar for the Minyan intends to fulfill the obligation of all listeners. [ibid]
 M”E 585/3; Ben Ish Chaiy Netzavim 14; Kaf Hachaim 585/12
 Seemingly however this only applies to the first day of Rosh Hashanah. However on the second day of Rosh Hashanah one may be lenient and is not required to rehear the blowing. [See 585/6; Kaf Hachaim 589/40 and 47; Vetzaruch Iyun as this difference is not mentioned in Poskim. See however 475/29 that there is a dispute if Rabbinical commands require intent and Admur rules that it is proper to be stringent even Bedieved. However here that one is in doubt certainly it seems that he may be lenient.]
 As since he stopped walking there is a Chazaka that he had intent to fulfill his obligation. [ibid]
 As his original intent of his coming to Shul to fulfill his obligation is carried into his current hearing. [ibid]
 As Mitzvos require intent in order for one to fulfill his obligation with them. [ibid]
 The reason for this is because every blow must be valid in its entirety, from beginning to end, for it to be considered a Kosher sound. Hence since in this case the sound only became valid in its middle, it therefore is not considered a Kosher blow. [ibid]
 M”B 60/10
 Chayeh Adam Klal 68
 Thus if he read Shema during prayer or ate Matzah during the Seder or blew Shofar or shook Lulav he fulfills his obligation even if he did not have explicit intent as it is clearly evident that he is only doing these matters in order to do the Mitzvah. [ibid]