Skip to content

📱An Android photo picker to search and download photos from Unsplash.

License

Notifications You must be signed in to change notification settings

unsplash/unsplash-photopicker-android

Repository files navigation

Unsplash Photo Picker for Android

License JitPack

UnsplashPhotoPicker is an Android UI component that allows you to quickly search the Unsplash library for free high-quality photos with just a few lines of code.

iOS photo picker here.

Unsplash Photo Picker for Android preview

Table of Contents

Description

UnsplashPhotoPicker is a Kotlin object you use to initialize the library. You present the picker by navigating to the UnsplashPickerActivity to offer your users to select one or multiple photos from Unsplash. Once they have selected photos, the UnsplashPickerActivity returns UnsplashPhoto objects that you can use in your app.

Requirements

Installation

Gradle

To integrate UnsplashPhotoPicker into your Android Studio project using Gradle, specify in your project build.gradle file:

allprojects {
   repositories {
      ...
      maven { url  'https://jitpack.io' }
   }
}

And in your app module build.gradle file, replacing x.y.x by the latest tag:

dependencies {
   implementation 'com.github.unsplash:unsplash-photopicker-android:x.y.z'
}

Usage

❗️Before you get started, you need to register as a developer on our Developer portal. Once registered, create a new app to get an Access Key and a Secret Key.

Configuration

The UnsplashPhotoPicker is a Kotlin object you need to use in order to initialize the library. Add this in your custom application class onCreate method:

UnsplashPhotoPicker.init(
            this, // application
            "your access key",
            "your secret key"
            /* optional page size */
        )
Property Type Optional/Required Default
application Application Required N/A
accessKey String Required N/A
secretKey String Required N/A
pageSize Int Optional 20

Presenting

In order to access the picker screen you need to navigate to the UnsplashPickerActivity. This activity has a getStartingIntent method to create the Intent needed:

startActivityForResult(
                UnsplashPickerActivity.getStartingIntent(
                    this, // context
                    isMultipleSelection
                ), REQUEST_CODE
            )

Using the results

Your calling activity must use a startActivityForResult method to be able to retrieve the selected UnsplashPhoto:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE) {
            val photos: ArrayList<UnsplashPhoto>? = data?.getParcelableArrayListExtra(UnsplashPickerActivity.EXTRA_PHOTOS)
            // use your photos here
        }
}

See UnsplashPhoto.kt for more details.

License

MIT License

Copyright (c) 2019 Unsplash Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

📱An Android photo picker to search and download photos from Unsplash.

Resources

License

Stars

Watchers

Forks

Packages

No packages published