An electronic device comprising: a memory ; and a processor electrically coupled to the memory, wherein the processor executing instructions stored in the memory is configured to: detect an insertion of earphones into a connector of the electronic device, acquire first polarity information stored in the memory, wherein the first polarity information is at least one of: polarity information corresponding to a number of uses greater than a threshold, and polarity information corresponding to the location of the electronic device, based on the first polarity information, set a sound path for inputting or outputting a sound to or from the electronic device, determine second polarity information corresponding to the inserted earphones, determine whether the first polarity information is compatible with the second polarity information, reset the sound path based on the second polarity information when the first polarity information is not compatible with the second polarity information, and update the polarity information stored in the memory by at least the number of uses of the second polarity information, and/or a location where the second polarity information is used. a memory ; and a processor electrically coupled to the memory, wherein the processor executing instructions stored in the memory is configured to: detect an insertion of earphones into a connector of the electronic device, acquire first polarity information stored in the memory, wherein the first polarity information is at least one of: polarity information corresponding to a number of uses greater than a threshold, and polarity information corresponding to the location of the electronic device, based on the first polarity information, set a sound path for inputting or outputting a sound to or from the electronic device, determine second polarity information corresponding to the inserted earphones, determine whether the first polarity information is compatible with the second polarity information, reset the sound path based on the second polarity information when the first polarity information is not compatible with the second polarity information, and update the polarity information stored in the memory by at least the number of uses of the second polarity information, and/or a location where the second polarity information is used. detect an insertion of earphones into a connector of the electronic device, acquire first polarity information stored in the memory, wherein the first polarity information is at least one of: polarity information corresponding to a number of uses greater than a threshold, and polarity information corresponding to the location of the electronic device, based on the first polarity information, set a sound path for inputting or outputting a sound to or from the electronic device, determine second polarity information corresponding to the inserted earphones, determine whether the first polarity information is compatible with the second polarity information, reset the sound path based on the second polarity information when the first polarity information is not compatible with the second polarity information, and update the polarity information stored in the memory by at least the number of uses of the second polarity information, and/or a location where the second polarity information is used. <EOS>