How to share the Particular SQLITE audio file to Gmail in android? - android

I am working audio recording app, in which the audio is recorded and stored inside the app and that path is stored in SQLITE.
I need that audio file to be shared in whatsapp/gmail or saved in internal directory of mobile.
I try to share them using the Intent but in whatsapp it showed unsupported format.
I tried this code
private void Shareoption(List<RecordData> uploadlist)
{
RecordData reco2 = uploadlist.get(0);
String id3 = reco2.getId();
final RecordData recordData = DBcreatedata.getData(id3);
final File f;
locname = recordData.getRecordDataTitle();
f = new File(recordData.getRecordData());
Uri uri = Uri.parse(f.getAbsolutePath() );
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, uri.toString());
startActivity(Intent.createChooser(share, "Share Sound File"));
And I also searched about this and I came to know that first the audio file must be stored in internal directory before sharing. So I tried input output stream method, it did not work.
Can any one help me to share this audio file ?

By using this I think your problem will be solved
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri shareFileUri= Uri.parse(string);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, shareFileUri);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(Intent.createChooser(sharingIntent, "Share Sound File"));

Related

Getting null.bin file after sharing a video in whatsapp from my app

I have stored a video file in the android raw folder and want to share it through WhatsApp. But I am getting the file in WhatsApp as null.bin.
private void shareVideo(){
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/raw/video_name");
Intent videoshare = new Intent(Intent.ACTION_SEND);
videoshare.setType("*/*");
videoshare.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
videoshare.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(videoshare);
}

How to play videos with phone's standard video player app

I want to play videos i have stored in the external storage with the phone's standard video Player app. I've tried using FileProvider, but I can't manage to pass the video to the player.
private void passVideo(String videoname){
File videoPath = new File(Environment.getExternalStorageDirectory(), "video_folder");
File newFile = new File(videoPath, videoname);
Uri path = FileProvider.getUriForFile(this, "com.example.provider", newFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType(getContentResolver().getType(path))
.setStream(path)
.getIntent();
shareIntent.setData(path);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Open Video..."));
}
With this code I manage to get the Chooser for gmail, whatsapp and other social media platforms, but that's not what I want and they all say they can't handle the file format anyway. It also gives the option to play the video with VLC, but it instantly crashes.
I have tried every possible file format and none of them works.
Sorry if I'm missing something obvious, I am still a beginner.
ShareCompat.IntentBuilder is for ACTION_SEND, which is not the typical Intent action for playing a video. ACTION_VIEW would be more typical. So, try:
private void passVideo(String videoname){
File videoPath = new File(Environment.getExternalStorageDirectory(), "video_folder");
File newFile = new File(videoPath, videoname);
Uri uri = FileProvider.getUriForFile(this, "com.example.provider", newFile);
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
viewIntent.setType(getContentResolver().getType(uri));
viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(viewIntent);
}

Whatsapp audio share

Uri uri = Uri.parse("android.resource://haydo.kufurbaz.kfrbazhaydosesleri/raw/oylemikesiliramk.wav");
Intent myınIntent = new Intent(Intent.ACTION_SEND);
myınIntent.setType("audio / wav");
String sharebody = ".mp3";
myınIntent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(myınIntent,"Share using"));
return true;
When i try to send someone audio to whatsapp it does not shown in format of wav or mp3 it
my file name in raw is : oylemikesiliramk.wav
help pls

Facebook messenger can't process my .wav file

I write the code like this. Also path is correct. But Facebook messenger can't hold my .wav file
String sharePath = "/storage/emulated/0/Recordings/test.wav";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/wav");
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Sound File"));
https://developers.facebook.com/docs/messenger/android
audio/wav is not a supported MIME TYPE. Check the above link for supported types

Android share ListView content

I have many items in my soundboard and i need to share them.I have tried this
private void shareImage(int resId) {
Intent share = new Intent(Intent.ACTION_SEND);
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("audio/mp3");
// Make sure you put example png image named myImage.png in your
// directory
String imagePath = "android.resource://com.example.app/" + resId;
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image!"));
}
but without succes! Thanks
Few, if any, Android apps are set up with an <intent-filter> that handles the android.resource scheme. Either copy the file to internal storage and use FileProvider, or just use my StreamProvider (which streams resources), to have a content Uri instead.
Make sure the resource path is correct.
Say, if you have an audio in your res/raw/song.mp3
then the path should be like this
String path = "android.resource://PACKAGENAME/res/" + Integer.toString(R.raw.song);
Example code like this..
private void shareAudio(int resId) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
String path = "android.resource://com.example.app/res/" + Integer.toString(resId);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
startActivity(Intent.createChooser(share, "Share Audio!"));
}
Try this...
Use the Uri.fromFile and put your File like this example:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
File your_file = new File("your path");
i.setType("plain/text");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(your_file));
startActivity(Intent.createChooser(i,"Share..."));

Categories

Resources