Skip to content Skip to sidebar Skip to footer

Make Soundclip In A Listview Selectable As (notification) Ringtone?

I've got a list of tones which I've made, I've managed to get them into a list but now I'm faced with the challenge of allowing the user to 'touch and hold' to assign as a notifica

Solution 1:

The solution I post is just making it possible for you to detect the position of the listitem you clicked and set as ringtone (which is not working), inside the setRingtone function the magic happens. all code to make the sound as ringtone must be placed in there

Inside the switch change the case id 'main_menu' to the item id from your menu -> context_menu.xml like below

<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:id="@+id/main_menu"android:title="@string/set_ringtone"android:showAsAction="ifRoom"
    /></menu>

Add beneath onCreateContextMenu the code below.

@OverridepublicvoidonCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
     super.onCreateContextMenu(menu, v, menuInfo);
     MenuInflaterinflater= getMenuInflater();
     inflater.inflate(R.menu.context_menu, menu);
   }
 }

 /*-----------------------------  add code below ------------------------------*/@OverridepublicbooleanonContextItemSelected(MenuItem item) {
        AdapterView.AdapterContextMenuInfo info;
        try {
            info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        } catch (ClassCastException e) {
            Log.e("", "bad menuInfo", e);
            returnfalse;
        }

        switch (item.getItemId()){
            case R.id.main_menu:
                setRingtone(item.getItemId(), info.position);
                //Toast.makeText(this, "id = " + item.getItemId() + " pos =     " + info.position, Toast.LENGTH_SHORT).show();break;
            default:
                returnfalse;
        }

        returntrue;
    }

    publicvoidsetRingtone(int id, int pos){
        //RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE, newUri);

        Toast.makeText(this, "id = " + id + " pos = " + pos, Toast.LENGTH_SHORT).show();
    }

Post a Comment for "Make Soundclip In A Listview Selectable As (notification) Ringtone?"