Hi,

that's due to a simple reason which i expect 
that is due to the absence of the directory

save the file to "/mnt/sdcard/navkarringtone.mp3" by removing "/Ringtones"
or make a directory /mnt/sdcard/Ringtones/ using this before you create a 
file out stream
File mp3Directory = new File("/mnt/sdcard/Ringtones/");
               mp3Directory.mkdirs();

then it works fine

and i suggest to add <uses-permission 
android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in manifest

all the best for the success,

Thanks,
shiva 



On Monday, November 19, 2012 4:17:43 AM UTC+5:30, Bhavik Kothari wrote:
>
> hi..
> While I save wallpaper ,its perfectly set . but when I set .mp3  file as 
> rington in emulator  its give error(I attach Error Photo). 
>
> I use below code for set wallpaper and ringtone. 
>
> If anyone have Idia about it,then Please send me reply.
>
> songnameview.setOnLongClickListener(new OnLongClickListener() {
>  public boolean onLongClick(View v) {
> // TODO Auto-generated method stub
>  String[] arrayfordialog=new String[]{"Wallpaper","Ringtone"};
>   AlertDialog.Builder builder = new 
> AlertDialog.Builder(NavkarSounds_FinalBuildActivity.this);
>     builder.setTitle("Save As ")
>            .setItems(arrayfordialog, new DialogInterface.OnClickListener() 
> {
>                @SuppressWarnings("static-access")
> public void onClick(DialogInterface dialog, int which) {
>                if(which==0)
>                {
>                WallpaperManager 
> wallpapermanager=WallpaperManager.getInstance(getApplicationContext());
>                try {
>                
>              Display display=getWindowManager().getDefaultDisplay();
>              int height=display.getHeight();
>              int width=display.getWidth();
>              Bitmap bit=BitmapFactory.decodeResource(getResources(), 
> ImageList[currenttrack]);
> wallpapermanager.setBitmap(Bitmap.createScaledBitmap(bit, width, height, 
> false));
>  } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>                }
>                else
>                {
>                InputStream in = 
> getResources().openRawResource(songidlist[currenttrack]);
>                FileOutputStream out;
>                try {
> out = new FileOutputStream("/mnt/sdcard/Ringtones/navkarringtone.mp3");
> byte[] buff = new byte[1024];
> int read = 0;
> while ((read = in.read(buff)) > 0) {
>       out.write(buff, 0, read);
> }
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>                catch(IOException ex)
>                {
>                
>                }
>               
>                String 
> path=Environment.getExternalStorageDirectory().getPath()+"/Ringtones/";
>                String filename="navkarringtone.mp3";
>                
>               File k = new File(path, filename);
>               ContentValues values = new ContentValues();
>                 values.put(MediaStore.MediaColumns.DATA, 
> k.getAbsolutePath());
>                 values.put(MediaStore.MediaColumns.TITLE,"Navkar 
> Ringtone");
>                 values.put(MediaStore.MediaColumns.MIME_TYPE, 
> "audio/mp3");
>                 values.put(MediaStore.Audio.Media.ARTIST, "");
>                 values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
>                 values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
>                 values.put(MediaStore.Audio.Media.IS_ALARM, false);
>                 values.put(MediaStore.Audio.Media.IS_MUSIC, false);
>
>                 //Insert it into the database
>                 Uri uri = 
> MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
>                 getContentResolver().delete(uri, 
> MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);
>                 Uri newUri = getContentResolver().insert(uri, values); 
>                
>  
> RingtoneManager.setActualDefaultRingtoneUri(NavkarSounds_FinalBuildActivity.this,
>  
> RingtoneManager.TYPE_RINGTONE, newUri);
>                
>                }
>            }
>            
>     });
>     builder.create();
>     builder.show();    
>     return true;
> }
> });
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to