According to Xiaomi's official document, you can set a custom ringtone when creating a message on the server side:
Call the extra(String key, String value) method of the message. The generator class sets the key to "sound _URI" and the value to the URI of the ringtone.
Ringtones can only use resources in the current app, and the URI format conforms to android.resource://yourpackagename/xxx/xxx.
The ringtone file is placed in the raw directory of Android app.
The stored sound file needs an extension, but don't write an extension in the uri.
The private message buildMessage () throws an exception {stringpackagename = "com.xiaomi.mipushemo"; String messagePayload = "This is a message"; String title = "notification title"; String description = "notification description"; Message message = new message. The builder (). Title (title). Description (description). Payload (messagePayload). Restricted package name (My package name). Pass through(0)// The message uses the notification bar. notifyType( 1)。 . Extra (constant. EXTRA_PARAM_SOUND_URI," Android . resource://"+package name+"/raw/shaking ")。 build(); Return message; }
Obviously, Xiaomi asked us to put the custom ringtone in the res/raw/ folder at the root of the Android APP project. Please note that this directory cannot have subfolders. I use Hbuilder cloud package, and there is no way to add sound resources to the res/raw folder in the cloud package. I consulted the official DCloud of hbuilder, and replied that this function is not supported for the time being, and I will add it later.
All right. Can I only pack offline? Redeploy all referenced sdk locally for ringtones? It's changed too much, so forget it.
In a flash, Park Yi thought of another idea: continue to package in the cloud and download the packaged apk file. We decompile, add the raw folder in the decompiled res directory, add audio files, such as shakingmp3.mp3, shakingaac.aac, then compile it into a new apk package, and then re-sign this new apk package!
According to the above ideas, I walked again and found it effective! Don't ask me how I came up with it, I won't tell you.