I have an app which lists the video from a location in SD card. I want to share the video on different possible apps(like Whatsapp, gmail, facebook or bluetooth etc.). What intent should I call to acheive this action? I found this: Share image from SD Card but it is for image sharing. I also read: http://developer.android.com/training/sharing/shareaction.html but I didn't get it. I am viewing the videos in a listview and want to display a list of possible apps where I can share the video when I click it in list view.
EDIT: I am using this for now:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM,uri_for_file);
sendIntent.setType("file/*");
startActivity(Intent.createChooser(sendIntent,"Send video via:"));
but showing error when I tried to share on bluetooth:
11-18 17:49:59.275: E/BluetoothLauncherActivity(3249): type is null; or sending file URI is null
I checked using debugger, the uri_for_file variable has the exact uri where the video is stored.
The problem was, uri_for_file was string and I needed to parse it to Uri. Sorry to bother.
New Code:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(uri_for_file));
sendIntent.setType("file/*");
startActivity(Intent.createChooser(sendIntent,"Send video via:"));
Related
In my app, I have an option to share photos using standard Android sharing mechanism. When I choose gmail or yahoo mail, the sharing works, the images are displayed in the body of an email and are sent to the destination. When I choose Facebook, the images are displayed inside the Facebook activity where you can add a message, but when I hit the Done button, the upload process starts, but always fails.
The title of the message box is: "Facebook Upload Failed" and the message itself is: "Your upload could not be completed because we could not access your photo(s)."
Here is the code snippet for sharing:
mShareIntent = new Intent();
mShareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
mShareIntent.setType("image/jpeg");
mShareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ArrayList<Uri> uris = new ArrayList<Uri>();
for(int i = 0; i < mImageUrls.size(); i++) {
uris.add(Uri.parse("file://"+mShareFiles[i].getAbsolutePath()));
}
mShareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(mShareIntent, "Share Images To..."))
The photos are obviously accessible, since they are successfully processed by gmail and yahoo mail. And Facebook, itself, can access them, but not sent them.
As an experiment, I shared photos from the Android Gallery, in the Chooser, I chose Facebook, and the photos were successfully uploaded.
Does anyone have any idea what might be going on?
Thank You,
Gary
If the file is in your app's private directory (or even in its sd card directory in KitKat) then you might run into sharing issues. And FileProvider has its problems too.
The only reliable way I've found to share image files is to copy them to the external storage directory for pictures and sharing from there (you can create a .nomedia subdirectory to avoid them appearing in the Gallery app).
For example:
Bitmap bitmapToShare = ...
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
File pictureStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File noMedia = new File(pictureStorage, ".nomedia");
if (!noMedia.exists())
noMedia.mkdirs();
File file = new File(noMedia, "shared_image.png");
saveBitmapAsFile(bitmapToShare, file);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
shareIntent.setType("image/png");
startActivity(shareIntent);
}
what is the correct way how I should form the intent to show content from my app in 3rd party viewers? I need to show images in gallery (or any other image viewer), pdfs in some pdf reader,..
Data gets server through a content provider which implements the openFile() method and returns a output pipe..
ParcelFileDescriptor[] pipe=ParcelFileDescriptor.createPipe();
...
ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
PipeThread pipeThread = new PipeThread(fileContents, stream);
pipeThread.start();
return pipe[0];
For images I use this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
I'm creating then a chooser for this intent as usual that's not the issue..
My problem is that although I see for example the Photos app in the chooser, I just cannot open the file in it..It just only opens the gallery with my images.
It's working when I use the action send, apps like gmail, drive, dropbox,..all of them are able to correctly read the image from the provider.
Also Skitch seems to be the only one app which I have tested it on that is able to open the image also using the Intent.ACTION_VIEW action..
Please don't tell me I should just send the URI, I really need to provide the file as a stream, or somehow as a serie of bytes (IPC limitations would be probably against this). I can't save the file to a public directory.
So the issue was that have been setting Intent type and data in two separate method calls..
What I didn't know is that Intent.setType() clears its data and Intent.setData() clears its type..
When I set both data and type through the Intent.setDataAndType() method call, it works even for URI pointing to a stream.
Unfortunately the final implementation is still not working flawlessly everywhere.
It works in default android gallery app, in G+ Photos app, in QuickPic, in Sony gallery app, but it does not work in default HTC gallery neither in default Samsung gallery.
Its just a pity, that its actually not that much dependent on my implementation as on how is it implemented in the 3rd party viewer app.
I wish to launch an intent which can allow me to choose images and videos together ath the same time. Currently I see that I can set type of intent as image or as video but not both together.
Intent intent = new Intent("android.intent.action.GET_CONTENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType("image/*");
OR
intent.setType("video/*");
Please suggest
Thanks
Am doing photo sharing in my application.for that am using Adding an Easy Share Action.it show only icon in the action bar,not options.so please suggest me with some example.
http://developer.android.com/training/sharing/shareaction.html
Easy Share is auto-populating; you only need to tell the ShareActionProvider what content it is you will be sharing.
Most of this is shared in the API link you provided, but if you are aiming to populate the list for the images you aim to be sharing, you would need to include this.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
Now that the shareIntent has been set to image, it will populate the list with the related apps, such as instagram, facebook or PhotoShop.
The app will view the images as a MIME type (Multipurpose Internet Mail Extension) in one of the types found here when you call shareIntent.setType.
I want to load images to my app and provide the user with an intent to show all the images available to him/her by using the intent.setType method:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/png");
Still, mp4 videos come up in the list even though there is a separate type for videos ("video/mp4") which I don't use (ever).
Is there a way to explicitly prevent videos from being shown in the list? Or is my only bet to check afterwards that the user hasn't selected a video?
The answer is to add this to your intent.
i.setType("image/*");