title: Making save to SD card and Context Menu functions dynamic, or relative to button pressed
body: <p>Relative to the below code, how do I make</p>
  
  <pre><code>if (savering(R.raw.sound1)){
  </code></pre>
  
  <p>and</p>
  
  <pre><code>String filename=”sound1″+”.ogg”;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>values.put(MediaStore.MediaColumns.TITLE, “sound1″);
  </code></pre>
  
  <p>dynamic instead of static so that the sound file that will be saved is based on the button pressed?</p>
  
  <p>My sound files are in a soundArray saved as sound1, sound2, sound3, etc. There is a button for each sound file. Click to play, long click brings up the below context menu.</p>
  
  <p>Any help or hints would be greatly appreciated.</p>
  
  <pre><code>//CONTEXT MENU
  
      @Override
      public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
       super.onCreateContextMenu(menu, v, menuInfo);
       menu.setHeaderTitle("Save as...");
       menu.add(0, v.getId(), 0, "Ringtone");
       menu.add(0, v.getId(), 0, "Notification");
      }
      @Override   
      public boolean onContextItemSelected(MenuItem item) { 
       if(item.getTitle()=="Ringtone"){function1(item.getItemId());}   
        else if(item.getTitle()=="Notification"){function2(item.getItemId());}  
        else {return false;}
       return true; 
      }
  
      public void function1(int id){  
       if 
       (savering(R.raw.sound1)){   
        // Code if successful   
        Toast.makeText(this, "Saved as Ringtone", Toast.LENGTH_SHORT).show(); 
       }           
       else           
       { 
        // Code if unsuccessful   
        Toast.makeText(this, "Failed - Check your SDCard", Toast.LENGTH_SHORT).show();
       }
  
      }
      public void function2(int id){   
       if 
       (savenot(R.raw.sound1)){   
        // Code if successful   
        Toast.makeText(this, "Saved as Notification", Toast.LENGTH_SHORT).show(); 
       }           
       else           
       { 
        // Code if unsuccessful   
        Toast.makeText(this, "Failed - Check your SDCard", Toast.LENGTH_SHORT).show(); 
       }
      }
  
  //Save into Ring tone Folder
  
      public boolean savering(int ressound){
       byte[] buffer=null;
       InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
       int size=0; 
  
       try {
         size = fIn.available();   
         buffer = new byte[size];   
         fIn.read(buffer);   
         fIn.close(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block   
        return false;      } 
  
       String path="/sdcard/media/audio/ringtones/";
       String filename="sound1"+".ogg"; 
  
       boolean exists = (new File(path)).exists();   
       if (!exists){new File(path).mkdirs();}   
  
       FileOutputStream save;
       try { 
        save = new FileOutputStream(path+filename);   
        save.write(buffer);   
        save.flush();   
        save.close();   
       } catch (FileNotFoundException e) { 
        // TODO Auto-generated catch block   
        return false;  
       } catch (IOException e) {
        // TODO Auto-generated catch block   
        return false;
       }
       sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename))); 
  
       File k = new File(path, filename);   
       ContentValues values = new ContentValues();   
       values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());   
       values.put(MediaStore.MediaColumns.TITLE, "sound1 Ringtone");   
       values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");   
       values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");   
       values.put(MediaStore.Audio.Media.IS_RINGTONE, true);   
       values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);   
       values.put(MediaStore.Audio.Media.IS_ALARM, true);   
       values.put(MediaStore.Audio.Media.IS_MUSIC, false);    
  
       //Insert it into the database
       this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
  
       return true; 
      }
  
  //Save in Notification Folder
  
      public boolean savenot(int ressound){
       byte[] buffer=null;
       InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
       int size=0; 
  
       try {
         size = fIn.available();   
         buffer = new byte[size];   
         fIn.read(buffer);   
         fIn.close(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block   
        return false;      } 
  
       String path="/sdcard/media/audio/notifications/";
       String filename="sound1"+".ogg"; 
  
       boolean exists = (new File(path)).exists();   
       if (!exists){new File(path).mkdirs();}   
  
       FileOutputStream save;
       try { 
        save = new FileOutputStream(path+filename);   
        save.write(buffer);   
        save.flush();   
        save.close();   
       } catch (FileNotFoundException e) { 
        // TODO Auto-generated catch block   
        return false;  
       } catch (IOException e) {
        // TODO Auto-generated catch block   
        return false;
       }
       sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename))); 
  
       File k = new File(path, filename);   
       ContentValues values = new ContentValues();   
       values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());   
       values.put(MediaStore.MediaColumns.TITLE, "sound1 Notification");   
       values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");   
       values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");   
       values.put(MediaStore.Audio.Media.IS_RINGTONE, true);   
       values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);   
       values.put(MediaStore.Audio.Media.IS_ALARM, true);   
       values.put(MediaStore.Audio.Media.IS_MUSIC, false);    
  
       //Insert it into the database
       this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
  
       return true; 
      }
  </code></pre>