An electronic device (101, 201, 430) comprising: a memory (130, 230); and a processor (120, 210, 400) electrically coupled to the memory, wherein the processor executing instructions stored in the memory is configured to: detect an insertion of earphones (460, 462, 464) 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 (130, 230); and a processor (120, 210, 400) electrically coupled to the memory, wherein the processor executing instructions stored in the memory is configured to: detect an insertion of earphones (460, 462, 464) 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 (460, 462, 464) 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.