How do I implement FileProvider in my sharing code? the app is presenting closures in android 8+ read something about the new system of android 8, and some recommended the replacement of the attempt by FileProvider, I already stated in the manifest and I created the XML file but I packed in this part, if someone can help me I will be very grateful.
obs: both context
are in red
private void sendWhatsAppAudio(int songIndex){
InputStream inputStream;
FileOutputStream fileOutputStream;
try {
inputStream = getResources().openRawResource(arrayAdapter.getItem(songIndex).getResId());
fileOutputStream = new FileOutputStream(
new File(Environment.getExternalStorageDirectory(), arrayAdapter.getItem(songIndex) +".mp3"));
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
}
inputStream.close();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Intent intent;
intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM,
FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + "/Brasil Memes" + arrayAdapter.getItem(songIndex) +".mp3"));
intent.setType("audio/*");
startActivity(createChooser(intent, "Quer compartilhar onde?"));
}