Home Menu

Menu



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


 
Herramientas
  #1  
Viejo 21/11/13, 17:17:46
Avatar de kaiser75
kaiser75 kaiser75 no está en línea
Miembro del foro
Mensajes: 493
 
Fecha de registro: ene 2011
Mensajes: 493
Modelo de smartphone: Vernee Mars, Galaxy S3
Tu operador: Orange
Mencionado: 3 comentarios
Tagged: 0 hilos
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   HTCMania > Todo sobre Android > Programación y Desarrollo para Android

Herramientas

Reglas de Mensajes
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Las caritas están On
Código [IMG] está On
Código HTML está Off

Saltar a Foro



Hora actual: 20:46:03 (GMT +1)

Cookies
Powered by vBulletin™
Copyright © vBulletin Solutions, Inc. All rights reserved.
 
HTCMania: líderes desde el 2007