Android RingtoneManager 铃声管理
package com.Aina.Android;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
public class Test extends Activity {
/** Called when the activity is first created. */
private Button btn1 = null;
private Button btn2 = null;
private Button btn3 = null;
private static final int Ringtone = 0;
private static final int Alarm = 1;
private static final int Notification = 2;
private static final String FileRingtone = Environment
.getExternalStorageDirectory()
+ "/music/ringtones";
private static final String FileAlarm = Environment
.getExternalStorageDirectory()
+ "/music/alarms";
private static final String FileNotification = Environment
.getExternalStorageDirectory()
+ "/music/notifications";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button) this.findViewById(R.id.Button01);
btn2 = (Button) this.findViewById(R.id.Button02);
btn3 = (Button) this.findViewById(R.id.Button03);
btn1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (isFile(FileRingtone)) {
// 打开系统铃声设置
Intent intent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
// 设置类型为来电
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_RINGTONE);
// 设置显示的标题
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
"设置来电铃声");
startActivityForResult(intent, Ringtone);
}
}
});
btn2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (isFile(FileAlarm)) {
Intent intent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
"设置闹钟铃声");
startActivityForResult(intent, Alarm);
}
}
});
btn3.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (isFile(FileNotification)) {
Intent intent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
"设置通知铃声");
startActivityForResult(intent, Notification);
}
}
});
}
/**
* 设置铃声之后的回调函数
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
} else {
// 得到我们选择的铃声
Uri uri = data
.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (uri != null) {
switch (requestCode) {
case Ringtone:
RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_RINGTONE, uri);
break;
case Alarm:
RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_ALARM, uri);
break;
case Notification:
RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_NOTIFICATION, uri);
break;
default:
break;
}
}
}
}
/**
* 判断文件是否存在,不存在则创建.
*
* @param path
* @return
*/
private boolean isFile(String path) {
boolean b = false;
File f = new File(path);
if (f.exists()) {
b = true;
} else {
if (f.mkdirs()) {
b = true;
} else {
b = false;
}
}
return b;
}
}
Java代码 收藏代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<Button android:text="设置来电铃声" android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button android:text="设置闹钟铃声" android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button android:text="设置通知铃声" android:id="@+id/Button03"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
Java代码 收藏代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Aina.Android"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Test"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
</manifest>
Android RingtoneManager 铃声管理的更多相关文章
- Android RingtoneManager铃声管理
本篇介绍一下跳转到系统铃声选择界面,android中的铃声通过RingtoneManager管理,RingtoneManager管理来电铃声(TYPE_RINGTONE).提示音(TYPE_NOTIF ...
- 如何编写程序设置Android来电铃声
我们在拿到新手机后通常会为其设置来年铃声,那么怎样通过代码来设置Android来电铃声,本文就为大家实例讲解下. 1.如果读到的是音频文件路径,需要先将音乐文件插入到多媒体库. Java代码 //设置 ...
- Android TelephonyManager电话管理器
今天介绍一下Android的电话管理器--TelephonyManager,TelephonyManager管理手机通话状态.电话网络信息的服务类,获取TelephonyManager: Teleph ...
- android 进程/线程管理(一)----消息机制的框架
一:android 进程和线程 进程是程序运行的一个实例.android通过4大主件,弱化了进程的概念,尤其是在app层面,基本不需要关系进程间的通信等问题. 但是程序的本质没有变,尤其是多任务系统, ...
- android 进程/线程管理(二)----关于线程的迷思
一:进程和线程的由来 进程是计算机科技发展的过程的产物. 最早计算机发明出来,是为了解决数学计算而发明的.每解决一个问题,就要打纸带,也就是打点. 后来人们发现可以批量的设置命令,由计算机读取这些命令 ...
- android 进程/线程管理(三)----Thread,Looper / HandlerThread / IntentService
Thread,Looper的组合是非常常见的组合方式. Looper可以是和线程绑定的,或者是main looper的一个引用. 下面看看具体app层的使用. 首先定义thread: package ...
- android 进程/线程管理(四)续----消息机制的思考(自定义消息机制)
继续分析handler 和looper 先看看handler的 public void dispatchMessage(Message msg) { if (msg.callback != null) ...
- android 进程/线程管理(四)----消息机制的思考(自定义消息机制)
关于android消息机制 已经写了3篇文章了,想要结束这个系列,总觉得少了点什么? 于是我就在想,android为什么要这个设计消息机制,使用消息机制是现在操作系统基本都会有的特点. 可是andro ...
- android的布局管理器
理论上通过setContentView(view)能够把一个view设置到activity中,但当你有很多个view控件的时候,就需要用android的布局管理器来管理view控件了. android ...
随机推荐
- HDU 5889 Barricade (Dijkstra+Dinic)
思路: 首先 先Dijkstra一遍 找出来最短路 不是最短路上的边都不要 然后呢 套个Dinic模板就好了-- 求个最小割 输出 大功告成~~ //By SiriusRen #include < ...
- POJ 1191 记忆化搜索
(我是不会告诉你我是抄的http://www.cnblogs.com/scau20110726/archive/2013/02/27/2936050.html这个人的) 一开始没有想到要化一下方差的式 ...
- 是时候抛弃web.xml了?
你是否再为配置文件web.xml容易出错而烦恼?是否为web.xml文件存放位置而不知所措?是否为web.xml为什么要这样配?怎么才能更好的配置web.xml而烦恼?那么一种新的方式出现了: spr ...
- Android控件-TabHost(二)
这边再补充一种更为灵活的方法,可以把TabWidget隐藏,用(RadioGroup+RadioButton)来代替,并利用监听器的方式来实现监听点击点击跳转Activity. 在讲解之前,先补充几点 ...
- matlab中plot画图参数的设置
原文链接:http://blog.sciencenet.cn/blog-281551-573856.html 一.Matlab绘图中用到的直线属性包括: (1)LineStyle:线形 (2)Line ...
- BFC 和 haslayout
在解释 BFC 是什么之前,需要先介绍 Box.Formatting Context的概念. Box: CSS布局的基本单位 Box 是 CSS 布局的对象和基本单位, 直观点来说,就是一个页面是由很 ...
- react-native signatures do not match the previously installed version;
原因:手机上已经安装过打包后的apk应用,与真机调试无法共存. 解决办法:删除手机上已经安装过的apk应用.
- Django_模型操作
- 洛谷 P2690 接苹果
P2690 接苹果 题目背景 USACO 题目描述 很少有人知道奶牛爱吃苹果.农夫约翰的农场上有两棵苹果树(编号为1和2), 每一棵树上都长满了苹果.奶牛贝茜无法摘下树上的苹果,所以她只能等待苹果 从 ...
- SQL解析器的性能測试
对同一个sql语句,使用3种解析器解析出ast语法树(这是编译原理上的说法,在sql解析式可能就是解析器自己定义的statement类型).运行100万次的时间对照. package demo.tes ...