Problem description
The code for scanning a local music file and placing it in the list is as follows:
Public list <localmp3> getlistbylocal () {cursor = getcontentresolver (). query (mediastore. audio. media. external_content_uri, null, mediastore. audio. media. default_sort_order); List <localmp3> localmp3s = new arraylist <localmp3> (); For (INT I = 0; I <cursor. getcount (); I ++) {localmp3 localmp3 = new localmp3 (); cursor. movetonext (); String title = cursor. getstring (cursor. getcolumnindex (Medias Tore. audio. media. title); string artist = cursor. getstring (cursor. getcolumnindex (mediastore. audio. media. artist); long duration = cursor. getlong (cursor. getcolumnindex (mediastore. audio. media. duration); string mp3url = cursor. getstring (cursor. getcolumnindex (mediastore. audio. media. data); int ismusic = cursor. getint (cursor. getcolumnindex (mediastore. audio. media. is_music); // determines whether the music is if (ismusic! = 0) {localmp3.settitle (title); localmp3.setartist (artist); localmp3.setduration (duration); localmp3.setmp3url (mp3url); localmp3s. Add (localmp3);} return localmp3s ;}
There is only one music file in the simulator, and the file name is all English,
Test and generate a list in the simulator. all garbled characters with question marks are displayed,
Use a real machine for testing. Some are garbled characters and some can be displayed normally (some Chinese can also be displayed normally ),
How can I solve this garbled problem? I hope you can help me find a solution on the Internet! Solution 1
In the getlistbylocal function, you must execute cursor. Close (). Otherwise, garbled characters may occur (this is related to memory management in cursor ). Solution 2
Do you use a simulator to test whether your English is full-width?
Cursor scans local music files, and garbled characters also appear in English names. How can this problem be solved.