Avisos

Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android

Respuesta
 
Herramientas
  #1  
Viejo 21/11/13, 17:17:46
Array

[xs_avatar]
kaiser75 kaiser75 no está en línea
Miembro del foro
 
Fecha de registro: ene 2011
Mensajes: 493
Modelo de smartphone: Vernee Mars, Galaxy S3
Tu operador: Orange
Usar sonido como tono o notificaciones

Tengo una lista de sonidos la cual al dejar pulsado sobre los botones sale un "context menu" donde decidir si se comparte el sonido, se usa como tono o como notificacion, tengo el codigo hecho y guarda correctamente el sonido como tono o notificacion, pero el problema es que me guarda el mismo sonido en todos los botones, eso es porque uso "R.raw.misonido" (para hacer la prueba) en la funcion que tengo definida, y la pregunta es, como puedo hacer para que me guarde el sonido correspondiente al boton que se pulse?... quizas con arrays? os agradezco cualquier ayuda.

Este es mi codigo:

1- Registro los botones para el context menu

registerForContextMenu(btn_sonido);
registerForContextMenu(btn_sonido2);
registerForContextMenu(btn_sonido3);
... i asi hasta 30 botones

2 - Defino el "onCreateContextMenu" y el "onContextItemSelected"

3 - Funcion para usar sonido como notificacion:

public void function2(int id){
// Guardar como notificacion
if (savenot(R.raw.misonido)) {
Toast.makeText(this, "Guardado como Notificacion", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, "Fallo, Revisa la SD", Toast.LENGTH_SHORT).show();
}

4 - La funcion sigue para guardar el sonido.

(Click para mostrar/ocultar)
public boolean savenot(int ressound){
byte[] buffer=null;
InputStream fIn = getBaseContext().getResources().openRawResource(re ssound);
int size=0;

try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
} catch (IOException e) {
return false;
}

String path="/sdcard/media/audio/notifications/";
String filename="Titulo del Sonido"+".mp3";

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, "Titulo del Sonido");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, "Artista");
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);

this.getContentResolver().insert(
MediaStore.Audio.Media.getContentUriForPath(k.getA bsolutePath()), values);

return true;
}

Última edición por kaiser75 Día 21/11/13 a las 17:28:01.
Responder Con Cita


Respuesta

Estás aquí
Regresar   Portal | Indice > Todo sobre Android > Programación y Desarrollo para Android



Hora actual: 19:50:03 (GMT +1)



User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.

Contactar por correo / Contact by mail / 邮件联系 /