Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.68 KB

Passing-an-image-to-the-app.md

File metadata and controls

39 lines (30 loc) · 1.68 KB

Passing an image to the app

Developers who wish to pass an image from their app to the Wikimedia Commons app can do so using an Intent, just like you would with any other app.

public void shareImage() {
    Uri imageUri = // your image URI
        
    Intent shareIntent = new Intent();
    shareintent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    startActivity(Intent.createChooser(shareIntent, "Send Image To"));
}

Developers can also add pass along a title and description with the image, which is highly recommended for the best user experience.

private static final String INTENT_TITLE_KEY = "title";
private static final String INTENT_DESCRIPTION_KEY = "description";

public void shareImage() {
    Uri imageUri = // your image uri

    String imageTitle = ""; // The title of the image you want to share, for instance "Joe Biden climbing Eiffel Tower"
    String imageDescription = ""; // Further description of the image you want to share, for instance "Taken a the third floor, after meeting reporters"

    Intent shareIntent = new Intent();
    shareintent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    shareIntent.putExtra(INTENT_TITLE_KEY, imageTitle);
    shareIntent.putExtra(INTENT_DESCRIPTION_KEY, imageDescription);
    startActivity(Intent.createChooser(shareIntent, "Send Image To"));
}

A sample Android application (written in Kotlin) demonstrating this functionality can be found in the commons-app/commons-intent-client-sample repository.