Save as Ringtone from ContextMenu

Posted by kostas_menu on Stack Overflow See other posts from Stack Overflow or by kostas_menu
Published on 2010-12-26T17:27:07Z Indexed on 2010/12/26 23:54 UTC
Read the original article Hit count: 199

Filed under:

I have created a button that onClick plays a mp3 file.I have also create a context menu that when you press the button for 2 secs it prompts you to save it as ringtone.How can i save it somewhere in my sd?this is my code:

 public void onCreate(Bundle icicle)  
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);  

        Toast.makeText(a.this, "Touch and listen", Toast.LENGTH_SHORT).show();

         Button button = (Button) findViewById(R.id.btn1);  
         registerForContextMenu(button);
        button.setOnClickListener(new View.OnClickListener() {  
           public void onClick(View v){

               MediaPlayer mp = MediaPlayer.create(a.this, R.raw.myalo);
               mp.start(); 
               Toast.makeText(a.this, "Eisai sto myalo", Toast.LENGTH_SHORT).show();

           }      

        });         
    @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");  

 }  

    @Override  
    public boolean onContextItemSelected(MenuItem item) {  
        if(item.getTitle()=="Ringtone"){function1(item.getItemId());}  

        else {return false;}  
    return true;  
    }  

    public void function1(int id){  
        Toast.makeText(this, "Ringtone Saved", Toast.LENGTH_SHORT).show();  

    }  



}  

© Stack Overflow or respective owner

Related posts about android