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

现在,我想检测内部存储器以及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/

10-12 04:00