Electronic device for detecting accessory device and method for operating same

The present invention relates to an electronic device for detecting an accessory device and a method for operating the same, the electronic device comprising: an external housing including a first surface facing a first direction, a second surface facing a second direction opposite to the first direction, and a side surface surrounding at least a part of the space between the first surface and the second surface; a user interface exposed through at least a part of the first surface, the second surface, and/or the side surface of the housing; a communication circuit disposed inside the housing; a first sensor disposed inside the housing; a conductive member electrically connected to the first sensor and disposed adjacent to at least a part of the second surface and/or the side surface of the housing; a processor electrically connected to the communication circuit, the user interface, and the first sensor; and a memory electrically connected to the processor, wherein the memory may store instructions which, when executed, cause the processor to: detect whether the accessory device configured to be detachably mounted on the second surface of the housing comes into contact with or approaches the conductive member, using the first sensor so as to generate a first signal; compare the first signal with at least one threshold value; perform at least one action through the communication circuit and/or the user interface, on the basis of the result of the comparison. Other embodiments are also applicable.