In December 2016, it was announced that Hanni was called up to the national team by Manager Georges Leekens for the Africa Cup of Nations in Gabon. He then scored his first Algeria goal, scoring an equaliser, in a 3–1 win against Mauritania on 7 January 2017. After appearing as an unused substitute in the first match of the Group Stage, he scored his first goal of the tournament, having come on in the 74th minute and scored a late consolation, in a 2–1 loss against Tunisia on 19 January 2020. However, Algeria were eliminated in Group B stage. Following the tournament, Hanni scored the next two goals against Guinea and Togo.