【问题标题】:Default "beep beep" alarm ringtone默认“哔哔”闹钟铃声
【发布时间】:2015-06-10 14:17:05
【问题描述】:

Andrid 手机上是否有一些默认的、可以安全使用的“哔哔”风格的铃声?

我有以下代码

final Ringtone alarm = RingtoneManager.getRingtone(getActivity(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
alarm.setStreamType(AudioManager.STREAM_ALARM);
alarm.play();

它会播放早上叫醒我的闹钟铃声,这是一些舒缓的音乐。但我需要一些更警觉的东西。

当然,我可以将一些声音文件打包到 apk,但我更喜欢使用设备上已有的一些声音。

【问题讨论】:

    标签: android ringtone


    【解决方案1】:

    在这里查看我的答案:

    How do I access Android's default beep sound?

    try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    这是一种列出设备中所有通知声音的方法

    public Map<String, String> getNotifications() {
        RingtoneManager manager = new RingtoneManager(this);
        manager.setType(RingtoneManager.TYPE_NOTIFICATION);
        Cursor cursor = manager.getCursor();
    
        Map<String, Uri> list = new HashMap<>();
        while (cursor.moveToNext()) {
            String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
            Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());
    
            list.put(notificationTitle, notificationUri);
        }
    
        return list;
    }
    

    找到“Helium”铃声后,使用它的 Uri 播放它:

     Uri heliumUri = findHeliumUri();
     Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
     r.play();
    

    【讨论】:

    • 嗯,通知可能会比警报更哔声,但它仍然会播放我的默认通知声音。我想要的是玩例如。 “氦气”(我在大多数设备中发现的声音之一),如果没有,播放用户的默认通知声音。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2020-09-03
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多