01 Random, Random creatures

Source: Internet
Author: User

Https://github.com/mlxy/RandomRingtones

Randomly change the ringtone on each call.

The result is that every time a call is ringing differently.

Written to s1er.

A few points of knowledge:

1. There is a Listfiles method in the file class, which was used in the first time when I was learning python. I don't know why I'm using it for now. The method receives a FilenameFilter parameter, fills in the anonymous class directly, and then overrides the Accept method The knowledge point is simply mentally retarded to not be able to take care of itself. Why should I write it alone? Well, I'm just writing a filter myself.

2. Change the system ringtone problem, look directly at the code.

1  Public Static voidSetringtone (Context context, File Ringtonefile) {2     //the properties of the ringtone. 3Contentvalues values =Newcontentvalues ();4 values.put (MediaStore.MediaColumns.DATA, Ringtonefile.getabsolutepath ());5 values.put (MediaStore.MediaColumns.TITLE, Ringtonefile.getname ());6Values.put (MediaStore.MediaColumns.MIME_TYPE, "Audio/mp3");7Values.put (MediaStore.Audio.Media.ARTIST, "");8 values.put (MediaStore.MediaColumns.SIZE, Ringtonefile.getusablespace ());9Values.put (MediaStore.Audio.Media.IS_RINGTONE,true);TenValues.put (MediaStore.Audio.Media.IS_NOTIFICATION,false); OneValues.put (MediaStore.Audio.Media.IS_ALARM,false); AValues.put (MediaStore.Audio.Media.IS_MUSIC,false); -  -     //Remove and reinsert from the Media Library.  theUri uri =MediaStore.Audio.Media.getContentUriForPath (Ringtonefile.getabsolutepath ()); -Context.getcontentresolver (). Delete (URI, MediaStore.MediaColumns.DATA + "=\" "+ ringtonefile.getabsolutepath () +" \ "" ,NULL); -Uri Newuri =context.getcontentresolver (). Insert (URI, values); -      +     //set a new ringtone.  - Ringtonemanager.setactualdefaultringtoneuri (context, Ringtonemanager.type_ringtone, Newuri); +}
Aoyama Davmar

Look at the ready-made code to change quite simple, it is difficult to rewrite themselves. So it's quite necessary to remember.

MimeType back to the asterisk should be able to support more audio types, but to own a test, simply let the use of MP3.

The artist fills it up casually.

The second step in the first to remove the ringtone from the Media Library is a very important step, many of the online code does not have this line, I did not test the time before this can not be used.

All that is left is the API call.

I think it is still not hard back, use to get the time to reproduce it.

3. After the Android3.1, the user manually forced to stop the application status and just before the installation is not open, so the broadcast receiver also failed. I have not figured out a solution for the moment, I do not know how the big rogue resides backstage.

Then hand-Draw an icon up.

01 Random, Random creatures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.