• 23、铃声设置


    Android系统的铃声

            Android本身提供了一些默认的铃声文件,这些文件都放在“/system/media/audio”目录中。如果是我们自己下载的铃声文件(一般为mp3音频文件),可以放在SD卡的music目录。铃声主要有3种:一般的铃声(如来电铃声)、闹钟铃声和通知铃声。这3种铃声要分别放在如下的目录。

    /sdcard/music/ringtones:一般的铃声,如来电铃声。
    /sdcard/music/alarms:闹钟铃声。
    /sdcard/music/notifications:警告或通知铃声。
    调用铃声设置窗口
    RingtoneManager.TYPE_RINGTONE:设置来电铃声
    RingtoneManager.TYPE_ALARM:设置闹钟铃声
    RingtoneManager.TYPE_NOTIFICATION:设置通知铃声
    Demo
     
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="fill_parent"
     4     android:layout_height="fill_parent"
     5     android:orientation="vertical" >
     6 
     7     <Button
     8         android:layout_width="fill_parent"
     9         android:layout_height="wrap_content"
    10         android:onClick="onClick_Call_Ringtone"
    11         android:text="设置来电铃声" />
    12 
    13     <Button
    14         android:layout_width="fill_parent"
    15         android:layout_height="wrap_content"
    16         android:onClick="onClick_Alarm_Ringtone"
    17         android:text="设置闹铃声音" />
    18 
    19     <Button
    20         android:layout_width="fill_parent"
    21         android:layout_height="wrap_content"
    22         android:onClick="onClick_Notification_Ringtone"
    23         android:text="设置通知铃声" />
    24 
    25 </LinearLayout>
     1 import android.app.Activity;
     2 import android.content.Intent;
     3 import android.media.RingtoneManager;
     4 import android.net.Uri;
     5 import android.os.Bundle;
     6 import android.view.View;
     7 
     8 public class Main extends Activity {
     9 
    10     @Override
    11     public void onCreate(Bundle savedInstanceState) {
    12         super.onCreate(savedInstanceState);
    13         setContentView(R.layout.main);
    14 
    15     }
    16 
    17     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    18         if (resultCode != RESULT_OK) {
    19             return;
    20         }
    21         Uri uri = data
    22                 .getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
    23 
    24         if (uri != null) {
    25             switch (requestCode) {
    26             case 1: // 来电铃声
    27                 RingtoneManager.setActualDefaultRingtoneUri(this,
    28                         RingtoneManager.TYPE_RINGTONE, uri);
    29 
    30                 break;
    31             case 2: // 闹钟铃声
    32                 RingtoneManager.setActualDefaultRingtoneUri(this,
    33                         RingtoneManager.TYPE_ALARM, uri);
    34                 break;
    35             case 3:
    36                 RingtoneManager.setActualDefaultRingtoneUri(this,
    37                         RingtoneManager.TYPE_NOTIFICATION, uri);
    38                 break;
    39             default:
    40                 break;
    41             }
    42         }
    43     }
    44 
    45     public void onClick_Call_Ringtone(View view) {
    46         Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    47 
    48         intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
    49                 RingtoneManager.TYPE_RINGTONE);
    50         intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置来电铃声");
    51         startActivityForResult(intent, 1);
    52     }
    53 
    54     public void onClick_Alarm_Ringtone(View view) {
    55         Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    56 
    57         intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
    58                 RingtoneManager.TYPE_ALARM);
    59         intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置闹钟铃声");
    60         startActivityForResult(intent, 2);
    61     }
    62 
    63     public void onClick_Notification_Ringtone(View view) {
    64         Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    65 
    66         intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
    67                 RingtoneManager.TYPE_NOTIFICATION);
    68         intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置通知铃声");
    69         startActivityForResult(intent, 3);
    70     }
    71 
    72 }
    1 <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
     
     
  • 相关阅读:
    LyX – The Document Processor
    An HTML5 presentation builder — Read more
    R语言定义
    A Hybrid User and ItemBased Collaborative Filtering with Smoothing on Sparse Data
    RapidMiner
    http://www.rseek.org一个查找R资料的站点
    An HTML5 presentation builder — Read more
    R代码脚本的运行
    data ming with R a book
    A Hybrid User and ItemBased Collaborative Filtering with Smoothing on Sparse Data
  • 原文地址:https://www.cnblogs.com/androidsj/p/3935130.html
Copyright © 2020-2023  润新知