콜백 -> Android Kotlin 라이브러리를 사용하여 다른 애플리케이션과 이미지 공유

Share-Em

Kotlin Coroutines가 지원하는 Android용 ImageText 공유 라이브러리. Share는 다음과 같습니다.

  • 빠름: ShareBackground Thread를 사용하여 Coroutines에서 작업을 수행합니다.

  • 경량: Share APK에 ~10개 메서드를 추가합니다(이미 코루틴을 사용하는 앱의 경우).

  • 사용 용이성: Share's API는 단순성과 최소한의 상용구를 위해 Kotlin의 언어 기능을 활용합니다.

  • 현대: Share 코루틴을 사용합니다.

  • 구현


    Sharejitpack에서 사용할 수 있습니다.

    그라들



    루트build.gradle 파일(모듈/앱 build.gradle 파일 아님)에 아래 코드를 추가하세요.

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

    그리고 APP의 build.gradle 파일에 종속성 코드를 추가합니다.

    dependencies {
    
          implementation 'com.github.EsmaeelNabil:Share-em:1.0.7'
    
    }
    

    용법



    간단한 사용법


  • 이미지만 공유

  • Share.with(context = this)
                .item(SharableItem(pictureUrl = "ImageUrl"),
                    onStart = {},
                    onFinish = { isSuccessful, errorMessage -> })
    

  • A 텍스트만 공유

  • Share.with(context = this)
                .item(SharableItem(data = "Text To Share"),
                    onStart = {},
                    onFinish = { isSuccessful, errorMessage -> })
    

    더 구체적인 예



    
    Share.with(context = this).item(SharableItem(
            pictureUrl = "https://images.unsplash.com/photo-1554290712-e640351074bd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=965&q=80",
            data = "body text",                       //default = ""
            shareAppLink = false,                    // don't generate appliaction playstore `download our app` message with the data text. default = false
            downloadOurAppMessage = "Find us here"  // A custom message for AppLink sharing feature
        ),
    
            onStart = {
                // do something onStart like : Loading
                Log.e(TAG, "Sharing Started.")
            },
    
            onFinish = { isSuccessful: Boolean, errorMessage: String ->
    
                // if isSuccessful : you will see an intent chooser
                // else            : check the error message
    
                if (isSuccessful)
                    Log.e(TAG, "Successfully shared")
                else
                    Log.e(TAG, "error happened : $errorMessage")
    
            }
        )
    
    


  • pictureUrl = "ImageUrl"valid URL이 아닌 경우 data 텍스트만 공유하게 됩니다.
  • downloadOurAppMessage is provided and shareAppLink`가 false이면 무시됩니다.
  • 좋은 웹페이지 즐겨찾기