Bug
Some models (Android 4.4), such as nexus5, cannot be played after a custom ringtone is selected.
Cause of bug
The URI obtained by intent. setaction (intent. action_get_content) of some models in 4.4 Is
Content: // com.android.providers.media.doc uments/document/audio % 3a1407
This format of Uri does not recognize the error in the method of playing music.
The URI obtained by intent. setaction (intent. action_get_content) in analyticdb 4.3 and later versions is
Content: // media/external/Audio/Media/91613
Normal playback
Solution
The following is a description of the changes made to Android 4.4 APIs on the official Google website .android.com.
Storage accessframework
On previusversions of Android, if you want your app to retrieve a specific type of filefrom another app, it must invoke an intent with the action_get_content action. this action is still the appropriate way to request a file that you wantImportYour your app. however, Android 4.4 introduces the action_open_document action, which allows the user to select a file of a specific type and grant your applong-term read access to that file (possibly with write access) withoutimporting the file to your app.
It mentions:
Action_get_content can be used directly at or below 4.3, and at 4.4 or above, action_open_document is recommended officially
However, according to the instructions, action_get_content is usable, but action_open_document is recommended. However, if some 4.4 models (such as neuxs 5) still use the action_get_content method, the returned URI is completely different from 4.3. 4.3 returns a file path, while 4.4 returns content: // com.android.providers.media.doc uments/document/Audio: 3951. There is no path and only the URI of the audio number.
To solve this problem, we try to use the action_open_document action recommended by Google.
The test results show that the officially recommended action is used to solve the problem in the project.
The Code is as follows:
Original code:
Case1:
Intentintentmyringtone =NewIntent (
Intent.Action_get_content);
Intentmyringtone. settype ("audio /*");
Intentmyringtone. setaction (intent.Action_get_content);
Startactivityforresult (intentmyringtone,
Select_my_ringtone);
Break;
Code after modification:
Case1:
Intentintentmyringtone =NewIntent (
Intent.Action_get_content);
Intentmyringtone. settype ("audio /*");
If(Build. version.Sdk_int<19 ){
Intentmyringtone
. Setaction (intent.Action_get_content);
}Else{
Intentmyringtone
. Setaction (intent. action_open_document );
}
Startactivityforresult (intentmyringtone,
Select_my_ringtone);
Break;
Lessons learned
Model problems are sometimes accompanied by version issues. It is important to pay attention to different Android versions.
If the problem was not fixed in the early stage, the phone was always characterized as 4.4.
The keyword of Google search is also very important. Sometimes it determines the problem where you change the direction of the entire bug, and extract the correct search keyword to quickly find the relevant articles, providing experience for others to solve the problem.
Follow the Android version updates to learn important updates. Many bugs in the project are caused by the inapplicable code of the project after the Android version is updated.
In addition, many developers often encounter image retrieval problems.
Attachment of two addresses for the problem of getting the URI image file friend reference: http://blog.csdn.net/eastman520/article/details/17756817
Http://blog.csdn.net/tempersitu/article/details/20557383
This article is from the "hddevteam" blog, please be sure to keep this source http://hddev.blog.51cto.com/3365350/1548932
Report on the inability to play audio files in the project