반응형

만들기

    private fun shareURL(strJson:String){
        val a: ShareUrlVO = Gson().fromJson(strJson, ShareUrlVO::class.java)
        val i = Intent(Intent.ACTION_SEND)
        i.setType("text/plain")
        i.putExtra(Intent.EXTRA_SUBJECT,a.chooserTitle)// 공유했을때 제목
        i.putExtra(Intent.EXTRA_TEXT,a.url)//링크 url
        startActivity(Intent.createChooser(i, a.subject)); // 위 그림에 나오는 제목부분
    }
class ShareUrlVO {
    constructor()
    constructor(chooserTitle: String, subject: String, url: String) {
        this.chooserTitle = chooserTitle
        this.subject = subject
        this.url = url
    }
    var chooserTitle: String = ""
    var subject: String = ""
    var url: String = ""
}

 

사용

 val str:String = "{\n" +
         "  \"chooserTitle\": \"\\\"선택 타이틀\\\"\",\n" +
         "  \"subject\": \"\\\"제목\\\"\",\n" +
         "  \"url\": \"\\\"https://www.naver.com\\\"\"\n" +
         "}"
         
         
shareURL(str)

-참고 : https://github.com/codepath/android_guides/wiki/Sharing-Content-with-Intents

반응형

+ Recent posts