Android ringtonemanager ringtone Management

Source: Internet
Author: User
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 BT N2 = 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"; @ overridepublic 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 stubif (isfile (fileringtone) {// enable the system ringtone to set intent = new intent (ringtonemanager. action_ringtone_picker); // set the type to incoming call intent. putextra (ringtonemanager. extra_ringtone_type, ringtonemanager. type_ringtone); // you can specify the title intent. putextra (ringtonemanager. extra_ringtone_title, "set ringtone"); startactivityforresult (intent, ringtone) ;}}); btn2.setonclicklistener (New button. onclicklistener () {public void onclick (view v) {// todo auto-generated method stubif (isfile (filealarm) {intent = new intent (ringtonemanager. action_ringtone_picker); intent. putextra (ringtonemanager. extra_ringtone_type, ringtonemanager. type_alarm); intent. putextra (ringtonemanager. extra_ringtone_title, "Set alert tone"); startactivityforresult (intent, alarm) ;}}); btn3.setonclicklistener (New Bu Tton. onclicklistener () {public void onclick (view v) {// todo auto-generated method stubif (isfile (filenotification) {intent = new intent (ringtonemanager. action_ringtone_picker); intent. putextra (ringtonemanager. extra_ringtone_type, ringtonemanager. type_notification); intent. putextra (ringtonemanager. extra_ringtone_title, "set notification ringtone"); startactivityforresult (intent, notification) ;}}) ;}/ *** set the response after the notification ringtone Call the function */@ overrideprotected void onactivityresult (INT requestcode, int resultcode, intent data) {super. onactivityresult (requestcode, resultcode, data); If (resultcode! = Result_ OK) {return;} else {// get the selected ringtone 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; }}}/*** determines whether the file exists. If the file does not exist, it is created. ** @ 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 ;}}
<? 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 = "set ringtone" Android: id = "@ + ID/button01" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> </button> <button Android: TEXT = "Set alert tone" Android: Id = "@ + ID/button02" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> </button> <button Android: text = "set notification ringtones" Android: Id = "@ + ID/button03" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> </button> </linearlayout>
<?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> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.