Persisting the Ringtone I set?

All your problems with Audio, Video and Images.

Persisting the Ringtone I set?

Postby Th3sandm4n » Mon Apr 19, 2010 2:47 am

I followed the code here: viewtopic.php?p=32325 to set my ring tone. This works fine. In my code I create a dir /sdcard/rings/x.mp3. I can go to the ringtone list
Home Screen > Settings > Sound & Display > Phone Ringtone
and the ring tone is listed.

When i restart the emulator though, the ringtone isn't listed anymore. It is still in the sd card I can see, but it seems it's not persisting the fact that it is a ringtone through system reboots. Is this normal emulator behavior, or am I just missing something about how the Ringtones are managed system wide?

Thanks
Th3sandm4n
Freshman
Freshman
 
Posts: 8
Joined: Wed Mar 10, 2010 8:53 am

Top

Postby Th3sandm4n » Mon Apr 19, 2010 7:44 am

Actually, a more important issue I just got to was that running it on my actual phone doesn't work at all. My directory under /sdcard is empty (using astro and OI to browse).
Th3sandm4n
Freshman
Freshman
 
Posts: 8
Joined: Wed Mar 10, 2010 8:53 am

Postby Th3sandm4n » Mon Apr 19, 2010 8:08 am

So, here is my code. I have
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  2.  
  3.                 <uses-permission android:name="android.permission.WRITE_SETTINGS" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

declared in my manifest.xml right after </application> (I've moved it inside as well, still the same problem). Turns out I still don't have real "write" privileges because root.canWrite() == false.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /**
  2.  
  3.          * Creates a ringtone in the tmp directory
  4.  
  5.          * @param resourceId ID of the sound file you are using
  6.  
  7.          * @param resourceName Name of the resource, this will be used for the filename
  8.  
  9.          * @return A File of the mp3 file
  10.  
  11.          */
  12.  
  13.         private File createTempRingtone(int resourceId, String resourceName) {
  14.  
  15.                 // root of the sd card
  16.  
  17.                 File root = Environment.getExternalStorageDirectory();
  18.  
  19.                 if(!root.canWrite()) {
  20.  
  21.                         Log.e("Create Ring Tone", "Can not write in root dir "+root.getAbsolutePath());
  22.  
  23.                 }
  24.  
  25.                 String state = Environment.getExternalStorageState();
  26.  
  27.                 /*if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
  28.  
  29.                         // no sd card mounted
  30.  
  31.                         Log.e("Creating Temp Ring Tone", "No SD card inserted.");
  32.  
  33.                         return null;
  34.  
  35.                 }*/ //TODO debugging on phone this happens for some reason
  36.  
  37.                 String ringtonesPath = root.getAbsolutePath() + File.separator + "ringtoness" + File.separator;
  38.  
  39.                 String ringToneFileName = resourceName + ".mp3";
  40.  
  41.                 try {
  42.  
  43.                         InputStream is = getResources().openRawResource(resourceId);
  44.  
  45.                         File ringToneRoot = new File(ringtonesPath);
  46.  
  47.                         // create the charlie hodge dir if we need to
  48.  
  49.                         if(!ringToneRoot.exists()) {
  50.  
  51.                                 ringToneRoot.mkdir();
  52.  
  53.                         }
  54.  
  55.                         if(!ringToneRoot.exists()) {
  56.  
  57.                                 Log.e("Making Dir", "Didn't create the directory!>!?!");
  58.  
  59.                         }
  60.  
  61.                         // create the ring tone if we need to
  62.  
  63.                         File ringTone = new File(ringtonesPath+ringToneFileName);
  64.  
  65.                         if(!ringTone.exists()) {
  66.  
  67.                                 ringTone.createNewFile();
  68.  
  69.                         }
  70.  
  71.                         // write to the file
  72.  
  73.                         OutputStream out = new FileOutputStream(ringTone);
  74.  
  75.                         byte buf[]=new byte[1024];
  76.  
  77.                     int len;
  78.  
  79.                     while((len=is.read(buf))>0)
  80.  
  81.                     out.write(buf,0,len);
  82.  
  83.                     out.close();
  84.  
  85.                     is.close();
  86.  
  87.                     return ringTone;
  88.  
  89.                 } catch (Exception e) {
  90.  
  91.                         //something happnened
  92.  
  93.                         Log.e("Creating Temp Ring Tone", "Something happened when creating the ringtone: "+e.getMessage());
  94.  
  95.                         return null;
  96.  
  97.                 }
  98.  
  99.         }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Thanks
Th3sandm4n
Freshman
Freshman
 
Posts: 8
Joined: Wed Mar 10, 2010 8:53 am

Postby Th3sandm4n » Tue Apr 20, 2010 7:03 am

If anyone comes across this here are some things to note:
I have everything set up fine in the code above.
You cannot access the SD card when you are in usb mode, which is why it was failing before. Disconnect after you load the app, then run it and it works fine.
I guess the emulator doesn't save the system settings, but on my phone it persists just fine.
Th3sandm4n
Freshman
Freshman
 
Posts: 8
Joined: Wed Mar 10, 2010 8:53 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: MSNbot Media and 23 guests