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 ...
随机推荐
- BZOJ 4034 线段树+DFS序
思路: 先搞出来每个点的DFS序 (要有入栈和出栈两种状态的) 处理出来 线段树区间有多少入栈的和多少出栈的 加区间的时候就加(入-出)*wei 查前缀和 //By SiriusRen #includ ...
- Laravel 框架指定路由关闭 csrf
修改 app\Http\Middleware\VerifyCsrfToken.php 内容: <?php namespace App\Http\Middleware; use Closure; ...
- 使用Excel VBA(快捷键)(加菜单)
将excel宏安全性调到中: 按alt+f11进入vba编辑器: 记住以下快捷键: F7 代码窗口 F4 属性窗口 ctrl+R 工程资源窗口 F5 程序运行 TAb 代码缩进 SHIFT+TAB ...
- 【Redis发布订阅】
Redis通过PUBLISH.SUBSCRIBE等命令实现发布与订阅模式. 举例:QQ群的公告,单个发布者,多个收听着. *** 发布/订阅 PUBLISH 频道 消息 将消息发布到指定的频道. . ...
- crawlspider抽屉爬取实例+分布
创建项目 scrapy startproject choutiPro 创建爬虫文件 scrapy genspider -t crawl chouti www.xxx.com 进入pycharm 培训 ...
- 今日SGU 5.15
最近事情好多,数据库作业,没天要学2个小时java,所以更新的sgu就比较少了 SGU 131 题意:给你两种小块一种,1*1,一种2*2-1*1,问你填满一个m*n的矩形有多少钟方法,n和m小于等于 ...
- Swift学习笔记(2)--元组(Tuples)、Optional(可选值)、(Assertions)断言
1.Tuples(元组) 元组是多个值组合而成的复合值.元组中的值可以是任意类型,而且每一个元素的类型可以是不同的. 1>定义:使用()包含所有元素,用逗号分开,也可以对每个元素做命名 let ...
- 【转】flex中的labelFunction(combox和dataGrid)
Flex中,对于显示一个字段,只需要指定对应字段属性给labelField即可,当需要上述所需要的功能的时候就得做个转换了,在Flex的基于List的组件都有一个labelFunction方法能很简单 ...
- python 服务端判断客户端异常断开
在进行 python 套接字编程时,服务端程序要判断客户端是否异常断开[由于断电或者其他突发情况导致链接中断],可以通过以下几种方式判断: 1.如果通信协议中,设有心跳包,则可记录上次收到时间,将服务 ...
- 洛谷—— P1328 生活大爆炸版石头剪刀布
https://www.luogu.org/problem/show?pid=1328 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在< ...