Skip to content

6. Handling incoming shares

Kumar Bibek edited this page Mar 1, 2016 · 2 revisions

Handling incoming share intents

You need to have an activity that can handle incoming share intents.
<activity
    android:name=".MultiPickerShareActivity"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <!-- Configure specific file types that you want to handle -->
        <!-- <data android:mimeType="video/*" -->
        <data android:mimeType="*/*"/>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.OPENABLE" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.SEND_MULTIPLE"/>
        <!-- Configure specific file types that you want to handle -->
        <!-- <data android:mimeType="image/*" -->
        <data android:mimeType="*/*"/>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.OPENABLE" />
    </intent-filter>
</activity>
In your activity, check the content type.
private void handleMultipleShares() {
    if (type.startsWith("image")) {
        ImagePicker picker = new ImagePicker(this);
        picker.setImagePickerCallback(this);
        picker.submit(IntentUtils.getIntentForMultipleSelection(getIntent()));
    } else if (type.startsWith("video")) {
        VideoPicker picker = new VideoPicker(this);
        picker.setVideoPickerCallback(this);
        picker.submit(IntentUtils.getIntentForMultipleSelection(getIntent()));
    } else if (type.startsWith("application") || type.startsWith("file") || type.startsWith("*")) {
        FilePicker picker = new FilePicker(this);
        picker.setFilePickerCallback(this);
        picker.submit(IntentUtils.getIntentForMultipleSelection(getIntent()));
    } else if (type.startsWith("audio")) {
        AudioPicker picker = new AudioPicker(this);
        picker.setAudioPickerCallback(this);
        picker.submit(IntentUtils.getIntentForMultipleSelection(getIntent()));
    }
}
Finally, update your UI.
@Override
public void onImagesChosen(List<ChosenImage> images) {
    // Display Images
}

@Override
public void onError(String message) {
    // Handle error
}

@Override
public void onVideosChosen(List<ChosenVideo> videos) {
    // Display Videos
}

@Override
public void onAudiosChosen(List<ChosenAudio> audios) {
    // Display Audios
}

@Override
public void onFilesChosen(List<ChosenFile> files) {
    // Display Files
}
Clone this wiki locally