铃声设置

 1 // 显示和设置铃声
 2     @Override
 3     protected void onCreate(Bundle savedInstanceState) {
 4         super.onCreate(savedInstanceState);
 5         setContentView(R.layout.fragment_main);
 6 
 7     }
 8 
 9     public void onclick(View view) {
10         switch (view.getId()) {
11         // 来电铃声
12         case R.id.button1:
13             Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
14             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
15                     RingtoneManager.TYPE_RINGTONE);
16             intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置来电铃声");
17             startActivityForResult(intent, 1);
18             break;
19         // 闹钟铃声
20         case R.id.button2:
21             Intent intent2 = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
22             intent2.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
23                     RingtoneManager.TYPE_ALARM);
24             intent2.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置闹钟铃声");
25             startActivityForResult(intent2, 2);
26             break;
27         // 闹钟铃声
28         case R.id.button3:
29             Intent intent3 = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
30             intent3.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
31                     RingtoneManager.TYPE_NOTIFICATION);
32             intent3.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "设置通知铃声");
33             startActivityForResult(intent3, 3);
34             break;
35         }
36     }
37 
38     @Override
39     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
40         // TODO Auto-generated method stub
41         super.onActivityResult(requestCode, resultCode, data);
42         if (resultCode != RESULT_OK) {
43             return;
44         } else {
45             Uri uri = data
46                     .getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
47             if (uri != null) {
48                 switch (requestCode) {
49                 // 来电铃声
50                 case 1:
51                     RingtoneManager.setActualDefaultRingtoneUri(this,
52                             RingtoneManager.TYPE_RINGTONE, uri);
53 
54                     break;
55                 // 闹钟铃声
56                 case 2:
57                     RingtoneManager.setActualDefaultRingtoneUri(this,
58                             RingtoneManager.TYPE_ALARM, uri);
59                     break;
60                 // 闹钟铃声
61                 case 3:
62                     RingtoneManager.setActualDefaultRingtoneUri(this,
63                             RingtoneManager.TYPE_NOTIFICATION, uri);
64                     break;
65                 }
66             }
67         }
68     }
69 
70 }

 

posted @ 2017-05-31 17:02  张兮兮  阅读(277)  评论(0编辑  收藏  举报