The letter “i” has a dual usage in Italian orthography. It can represent the vowel /i/ (filo or idea) or the consonant /j/ (ieri or febbraio), but it can also a pure orthographic device to indicate the pronunciation of a preceding c or g letter as /tʃ/ or /dʒ/.
The consonant /j/ is always represented by i in current Italian, so we could well say the letter has a three-pronged usage. In the past one could find j representing /j/, the usage only survives in some toponyms or surnames and a few reimported latinisms such as junior and similar.
In the second case it is not pronounced at all. For instance
anca is pronounced /'an.ka/ (hip)
ancia is pronounced /'an.tʃa/ (reed)
However, this poses some problems because the tonic accent position is not generally marked in Italian orthography. A non minimal pair that could be tough for beginners is
maga /'ma.ga/ (sorceress)
magia /ma.'dʒi.a/ (magic, enchantment)
The second word has three syllables and the tonic accent is on the vowel [i]. How do I know? Because I know Italian! There's no hint from the orthography that can help to guess the right pronunciation.
Even the plural form doesn't help! The plural of camicia is spelled camicie, just like the plural of farmacia is farmacie. But camicie has three syllables, and farmacie still is four syllables /far.ma.'tʃi.e/.
In other cases it can help, because the plural of maga is maghe (the h keeps the /g/ pronunciation) and the plural of magia is magie.
One might say that in farmacia and magia the i has both functions active: vowel marker and “softener marker” for c or g. Unfortunately, the orthographic conventions of Italian don't help in correctly placing the tonic accent.
Only the dictionary can help, I'm afraid. Other examples:
bigia /'bi.dʒa/ (ash grey [feminine adjective])
bugia /bu.'dʒi.a/ (lie)
Belgio /'bel.dʒo/ (Belgium)
nostalgia /nos.tal.'dʒi.a/ (nostalgia, homesickness)
vocio /vo.'tʃi.o/ (clamour), with plural vocii (yes, with two i’s)
regia /'re.dʒa/ (royal [feminine adjective])
regia /re.'dʒi.a/ (direction [films or stage])
The last two words are written the same way, but pronounced very differently (thanks to DaG for mentioning them). There is also the pair of names
Lucio /'lu.tʃo/ [masculine]
Lucia /lu.'tʃi.a/ [feminine]
Both names come from Latin lux, but for some reasons the accent has been moved in the feminine version.