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 thereInside the
switch
change thecase id 'main_menu'
to theitem id
from yourmenu -> context_menu.xml
like below
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/main_menu" android:title="@string/set_ringtone" android:showAsAction="ifRoom" /> </menu>
Add beneath onCreateContextMenu
the code below.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
}
/*----------------------------- add code below ------------------------------*/
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
} catch (ClassCastException e) {
Log.e("", "bad menuInfo", e);
return false;
}
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:
return false;
}
return true;
}
public void setRingtone(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?"