JUCE: ContentSharer Class Reference

JUCE

- Main Page
- Related Pages
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ContentSharer Class Reference
juce_gui_basics » filebrowser

Functions that allow sharing content between apps and devices. More...

`#include <juce_ContentSharer.h>`

## Public Types
using | Callback = std::function< void(bool success, const String &errorText)>
| A callback of this type is passed when starting a content sharing session.

## Public Member Functions
| ContentSharer ()=delete

## Static Public Member Functions
static ScopedMessageBox | shareFilesScoped (const Array< URL > &files, Callback callback, Component *parent=nullptr)
| Shares the given files.
static ScopedMessageBox | shareTextScoped (const String &text, Callback callback, Component *parent=nullptr)
| Shares the given text.
static ScopedMessageBox | shareImagesScoped (const Array< Image > &images, std::unique_ptr< ImageFileFormat > format, Callback callback, Component *parent=nullptr)
| A convenience function to share an image.
static ScopedMessageBox | shareDataScoped (const MemoryBlock &mb, Callback callback, Component *parent=nullptr)
| A convenience function to share arbitrary data.

## Detailed Description

Functions that allow sharing content between apps and devices.

You can share text, images, files or an arbitrary data block.

## Member Typedef Documentation

## ◆ Callback

using ContentSharer::Callback = std::function<void (bool success, const String& errorText)>

A callback of this type is passed when starting a content sharing session.

When the session ends, the function will receive a flag indicating whether the session was successful. In the case of failure, the errorText argument may hold a string describing the problem.

## Constructor & Destructor Documentation

## ◆ ContentSharer()

ContentSharer::ContentSharer | ( |  | ) |
| delete

## Member Function Documentation

## ◆ shareFilesScoped()

static ScopedMessageBox ContentSharer::shareFilesScoped | ( | const Array< URL > & | files,
|  | Callback | callback,
|  | Component * | parent = `nullptr`
| ) |  |
| static

Shares the given files.

Each URL should be either a full file path or it should point to a resource within the application bundle. For resources on iOS it should be something like "content/image.png" if you want to specify a file from application bundle located in "content" directory. On Android you should specify only a filename, without an extension.

Upon completion you will receive a callback with a sharing result. Note: Sadly on Android the returned success flag may be wrong as there is no standard way the sharing targets report if the sharing operation succeeded. Also, the optional error message is always empty on Android.

Parameters

  files | the files to share
  callback | a callback that will be called on the main thread when the sharing session ends
  parent | the component that should be used to host the sharing view

## ◆ shareTextScoped()

static ScopedMessageBox ContentSharer::shareTextScoped | ( | const String & | text,
|  | Callback | callback,
|  | Component * | parent = `nullptr`
| ) |  |
| static

Shares the given text.

Upon completion you will receive a callback with a sharing result. Note: Sadly on Android the returned success flag may be wrong as there is no standard way the sharing targets report if the sharing operation succeeded. Also, the optional error message is always empty on Android.

Parameters

  text | the text to share
  callback | a callback that will be called on the main thread when the sharing session ends
  parent | the component that should be used to host the sharing view

## ◆ shareImagesScoped()

static ScopedMessageBox ContentSharer::shareImagesScoped | ( | const Array< Image > & | images,
|  | std::unique_ptr< ImageFileFormat > | format,
|  | Callback | callback,
|  | Component * | parent = `nullptr`
| ) |  |
| static

A convenience function to share an image.

This is useful when you have images loaded in memory. The images will be written to temporary files first, so if you have the images in question stored on disk already call shareFiles() instead. By default, images will be saved to PNG files, but you can supply a custom ImageFileFormat to override this. The custom file format will be owned and deleted by the sharer. e.g.

Graphics g (myImage);
g.setColour (Colours::green);
g.fillEllipse (20, 20, 300, 200);
Array<Image> images;
images.add (myImage);
ContentSharer::getInstance()->shareImages (images, myCallback);
Array
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:57
Array::add
void add(const ElementType &newElement)
Appends a new element at the end of the array.
Definition juce_Array.h:419
Graphics
A graphics context, used for drawing a component or image.
Definition juce_GraphicsContext.h:46
Colours::green
const Colour green
Definition juce_Colours.h:95

Upon completion you will receive a callback with a sharing result. Note: Sadly on Android the returned success flag may be wrong as there is no standard way the sharing targets report if the sharing operation succeeded. Also, the optional error message is always empty on Android.

Parameters

  images | the images to share
  format | the file format to use when saving the images. If no format is provided, a sensible default will be used.
  callback | a callback that will be called on the main thread when the sharing session ends
  parent | the component that should be used to host the sharing view

## ◆ shareDataScoped()

static ScopedMessageBox ContentSharer::shareDataScoped | ( | const MemoryBlock & | mb,
|  | Callback | callback,
|  | Component * | parent = `nullptr`
| ) |  |
| static

A convenience function to share arbitrary data.

The data will be written to a temporary file and then that file will be shared. If you have your data stored on disk already, call shareFiles() instead.

Upon completion you will receive a callback with a sharing result. Note: Sadly on Android the returned success flag may be wrong as there is no standard way the sharing targets report if the sharing operation succeeded. Also, the optional error message is always empty on Android.

Parameters

  mb | the data to share
  callback | a callback that will be called on the main thread when the sharing session ends
  parent | the component that should be used to host the sharing view

The documentation for this class was generated from the following file:

- juce_ContentSharer.h