android - Android中检测自定义通知声音的具体方法

标签 android android-mediaplayer android-sound

我目前正在为我的应用程序提供一项功能,即向用户显示所有可用的系统通知声音。

现在我想检测内存和 SD 卡中可能存在的自定义通知声音。

目前我正在考虑获取所有可用音频文件的列表,然后按持续时间过滤它们(因为通知声音的长度非常短)。

是否有更好的方法来检测设备上的自定义通知声音?具有相应代码的答案将不胜感激。

最佳答案

RingtoneManager.getCursor()给你一个方法来获取所有铃声。看下面的代码 RingtoneManager.getCursor() .

/**
364     * Returns a {@link Cursor} of all the ringtones available. The returned
365     * cursor will be the same cursor returned each time this method is called,
366     * so do not {@link Cursor#close()} the cursor. The cursor can be
367     * {@link Cursor#deactivate()} safely.
368     * <p>
369     * If {@link RingtoneManager#RingtoneManager(Activity)} was not used, the
370     * caller should manage the returned cursor through its activity's life
371     * cycle to prevent leaking the cursor.
372     * <p>
373     * Note that the list of ringtones available will differ depending on whether the caller
374     * has the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.
375     *
376     * @return A {@link Cursor} of all the ringtones available.
377     * @see #ID_COLUMN_INDEX
378     * @see #TITLE_COLUMN_INDEX
379     * @see #URI_COLUMN_INDEX
380     */
381    public Cursor getCursor() {
382        if (mCursor != null && mCursor.requery()) {
383            return mCursor;
384        }
385
386        final Cursor internalCursor = getInternalRingtones();
387        final Cursor mediaCursor = getMediaRingtones();
388
389        return mCursor = new SortCursor(new Cursor[] { internalCursor, mediaCursor },
390                MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
391    }

关于android - Android中检测自定义通知声音的具体方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45263134/

相关文章:

android - 每次安装的资源标识号是否都相同?

android - 需要有关 Android 声音处理的帮助/建议

Android - 如何在不停止 TimerTask 的情况下将 SoundPool 静音

Android 开启勿扰模式时不播放音效

android - 动态应用内购买

android - spinner setOnItemSelectedListner 在 Activity 创建时间触发

android - 无法使用 getInt() 但能够将 getString() 用于 sqlite 数据库

Android 浏览器媒体播放器(stagefright?)显示的媒体名称

java - 在 Android 中播放音频时出现故障