Android share ListView content - android

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..."));

Related

How to share the Particular SQLITE audio file to Gmail in 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"));

How to send any image file to a particular whatsapp contact through Custom Url Scheme

I got success in sending text to a particular WhatsApp contact using this code
private void openWhatsApp(String mobileNumber) {
String text = "Hi";
if(whatsappInstalledOrNot("com.whatsapp")){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("whatsapp://send?text="+text+ "&phone="+mobileNumber));
startActivity(browserIntent);
}else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Now I want to share imageFile along with the text. I got the file path but don't know how to put in that browserIntent. Please Help.
I know its too late to answer but incase any one wondering.
Here is how you can use intent to share image file on Whatsapp
Intent share = new Intent();
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");
// Make sure you put example png image named myImage.png in your
// directory
String imagePath = file; // here path to your image file
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
Log.e("media", String.valueOf(uri));
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(share);
PS NOTE: You cannot send image with text as I tried some but fail to achieve it but you can share image file only from above code

Want to pick image files from a specific folder but have all the files of gallery instead

Want to pick image files from a specific folder vaibhav but have all the files of gallery instead.
Code
File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Vaibhav/");
Log.e("Dir path",dir.toString());
dir.exists();
Uri uri = Uri.parse(dir.toString());
Intent browseIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.getContentUri(uri.toString()));
browseIntent.setType("image/jpg");
startActivityForResult(browseIntent, BROWSE_REQUEST);
Following Code Just Works Fine:
public void openFolder()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/Vaibhav/");
intent.setDataAndType(uri, "image/jpg");
startActivity(Intent.createChooser(intent, "Open folder"));
}
Use
browseIntent.setDataAndType(uri, "image/.");//Loads all image files
Instead of
browseIntent.setType("image/jpg");

Share Intent.ACTION_SEND

I would love to share a picture with a text or url.
I'm using this code but I am only sharing the image, and changing the order of the "type" makes me share both but only as email / gmail
What am I doing wrong? my code is:
edit1
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setType("*/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Wallpaper/1.jpg"));
share.putExtra(Intent.EXTRA_TEXT, "helloworld");
startActivity(Intent.createChooser(share, (getApplicationContext().getString(R.string.condividi))));
try this
File DoutFile = new File(path);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(DoutFile));
share.putExtra(Intent.EXTRA_TEXT,
"" + getResources().getString(R.string.app_name));
startActivity(Intent.createChooser(share, "Share Image"));
Specify MIME type also for the text. "text/plain" is the type of text data MIME. Try using "*/*" as MIME, so you can send any generic data type.
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
More info about ACTION_SEND_MULTPLE and handling MIME types:
http://developer.android.com/reference/android/content/Intent.html
If you want to send multiple files then use the following code :-
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Add any subject");
intent.setType("image/*"); /* sharing any type of image. Modify to your need */
ArrayList<Uri> files = new ArrayList<Uri>();
for(String path : filesToSend /* List of images you want to send */) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
files.add(uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); /* adding files to intent */
startActivity(intent);

Android share text and image

I need to share text+image via Facebook, email etc. Now, I use this code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text));
//Uri path = Uri.parse("android.resource://com.android.mypackage/" + R.drawable.arrow);
Uri path = Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");
intent.putExtra(Intent.EXTRA_STREAM, path );
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);
The problem is that when I use "arrow.png", it says "Couldn't show attachment" and doesn't attach image; when I remove .png, I cannot open attached file later.
Basically, I need to attach png from drawable and some text and share it via ACTION_SEND
Try to use
Uri.fromFile(new File("android.resource://com.android.mypackage/drawable/arrow.png"));
insted of
Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");
It will work fine if file descriptor will be valid.

Categories

Resources