Playing a selected ringtone in a app

All your problems with Audio, Video and Images.

Playing a selected ringtone in a app

Postby Anubispod » Sat Jul 11, 2009 4:06 pm

Hi , this is my first post to my first android app i intend to write. I hope i find some answers here , since in the 2 books i have (Android Application Development) and (Hello Android) are great if you want to learn basic things.

But i found more useful info here in the forum. But now i am stuck with a problem where noware on the net is a answer to that.

I have made a level and now i want to play a alarm sound from the alarms from the android phone.
I got so far that i use the PreferenceManager in my Settings.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package rabit.help.Crusoe_Tools;
  3.  
  4.  
  5.  
  6. import android.content.Context;
  7.  
  8. import android.os.Bundle;
  9.  
  10. import android.preference.PreferenceActivity;
  11.  
  12. import android.preference.PreferenceManager;
  13.  
  14.  
  15.  
  16. public class Settings extends PreferenceActivity {
  17.  
  18.         private static final boolean ALARM = true;
  19.  
  20.         private static final String ALARMSTR = "alarm_togle";
  21.  
  22.         private static final int VALUE = 2;
  23.  
  24.         private static final String VALUESTR = "list";
  25.  
  26.         private static final String SOUND = "";
  27.  
  28.         private static final String SoundSTR = "tone_select";
  29.  
  30.         @Override
  31.  
  32.         protected void onCreate(Bundle savedInstanceState) {
  33.  
  34.                 super.onCreate(savedInstanceState);
  35.  
  36.                 addPreferencesFromResource(R.xml.settings);
  37.  
  38.         }
  39.  
  40.  
  41.  
  42.         public static boolean getAlarmState(Context context) {
  43.  
  44.                 return PreferenceManager.getDefaultSharedPreferences(context)
  45.  
  46.                                 .getBoolean(ALARMSTR, ALARM);
  47.  
  48.  
  49.  
  50.         }
  51.  
  52.        
  53.  
  54.         public static int getAlarmValue(Context context) {
  55.  
  56.                 return PreferenceManager.getDefaultSharedPreferences(context)
  57.  
  58.                                 .getInt(VALUESTR, VALUE);
  59.  
  60.  
  61.  
  62.         }
  63.  
  64.        
  65.  
  66.         public static String getAlarmSound(Context context) {
  67.  
  68.                 return PreferenceManager.getDefaultSharedPreferences(context)
  69.  
  70.                                 .getString(SoundSTR, SOUND);
  71.  
  72.  
  73.  
  74.         }
  75.  
  76. }
  77.  
  78.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and the xml file looks like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3.  
  4. <?xml version="1.0" encoding="utf-8"?>
  5.  
  6. <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  7.  
  8.         <PreferenceCategory android:title="Level Settings"
  9.  
  10.                 android:key="level_settings">
  11.  
  12.                 <RingtonePreference android:title="Alarm Sound"
  13.  
  14.                         android:showSilent="false" android:key="tone_select"
  15.  
  16.                         android:showDefault="false" android:ringtoneType="notification"></RingtonePreference>
  17.  
  18.                 <CheckBoxPreference android:key="alarm_togle"
  19.  
  20.                         android:title="Alarm On/Off"></CheckBoxPreference>
  21.  
  22.                 <ListPreference android:key="list" android:title="Set Trigger Value"
  23.  
  24.                         android:entries="@array/sense_lable" android:entryValues="@array/sense_value"></ListPreference>
  25.  
  26.         </PreferenceCategory>
  27.  
  28. </PreferenceScreen>
  29.  
  30.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


but how do i now play the sound on a certain event in main activity ?
I tried it with the RingTone class but i cant figure it out ????

I hope some one can help : )


Best regards Anubis
I am so lost .. but i see some light ...
Anubispod
Freshman
Freshman
 
Posts: 2
Joined: Sat Jul 11, 2009 3:41 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests