Nothing but the title. My problem is that I can not share over audio networks stored in the Raw folder.
Nothing but the title. My problem is that I can not share over audio networks stored in the Raw folder.
I went crazy, but at the end I stumbled over the solution on the internet and I share them!
Any questions chew the link. link
//Mi boton que al mantener pulsado por un periodo va llamar al metodo compartir
buttonRep25= (Button)findViewById(button25);
buttonRep25.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
//llamada al metodo donde le damos los valores (int a1 ,String a2)
compartir(R.raw.futuru_por_pasado,"futuru_por_pasado.mp3");
return false;
}
});
//Metodo Compartir
public void compartir (int a1 ,String a2)
{
try {
// Abrimos el recurso y lo metemos en un bufer
InputStream ins = getResources().openRawResource(a1);
byte[] buffer = new byte[ins.available()];
ins.read(buffer);
ins.close();
// Grabamos el bufer en un fichero
String filename = getExternalCacheDir().toString() + a2;
FileOutputStream fos = new FileOutputStream(filename);
fos.write(buffer);
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File open = new File(getExternalCacheDir().toString() + a2);
final Intent comparte = new Intent(Intent.ACTION_SEND);
comparte.setType("audio/mp3");
comparte.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(open));
startActivity(Intent.createChooser(comparte,"Enviar a..."));
}