1

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

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

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

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

4

1 回答 1

1

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    }
于 2017-07-23T08:52:58.460 回答