ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [AOS] ์ด๋ฏธ์ง€ ๋ฌธ์ž๋ฉ”์‹œ์ง€ ์ „์†กํ•˜๊ธฐ
    2023. 4. 14. 15:51
    ๋ฐ˜์‘ํ˜•

     

     

    ๐Ÿฑ
    ์˜ค์†Œ๋ฆฌ์”จ, ์•ˆ๋“œ๋กœ์ด๋“œ๋Š” ์–ดํ”Œ์—์„œ ๋ฌธ์ž๋ฉ”์‹œ์ง€๋กœ ์ด๋ฏธ์ง€๋ž‘ ํ…์ŠคํŠธ ๋‹ด์•„์„œ ๋ชป๋ณด๋‚ด๋‚˜?
    ์•ˆ๋˜๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค~ (๋‹น๋‹น)
    ๐Ÿถ

     

     


    (์–ด... ์ด๊ฒŒ ๋˜๋„ค...?)
    ๐Ÿถ

     

     

     

     

     

     

     

     

    ์–ดํ”Œ์—์„œ ๋ฌธ์ž๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋Š” ๊ฒฝ์šฐ๋Š” ๋ณดํ†ต ํ•ด๋‹น ์„œ๋น„์Šค์˜ ์ด๋ฒคํŠธ ๊ณต์œ  ๊ธฐ๋Šฅ์„ ์ด์šฉํ•  ๋•Œ์ด๋‹ค.

    ์ด๋ฒคํŠธ ๊ณต์œ ๋ฅผ ํ•ด๋ณด๋ฉด ๋ฉ”์‹œ์ง€ ๋‚ด์šฉ์— url๊ณผ ํ•ด๋‹น ์ด๋ฒคํŠธ์˜ ๊ฐ„๋žตํ•œ ์ •๋ณด๋งŒ์ด ๋‹ด๊ฒจ์žˆ๊ธฐ ๋งˆ๋ จ์ด๋‹ค.

    ์‚ฌ์šฉ์ž์—๊ฒŒ ์œ ๋ฃŒ MMS ์ „์†ก ๋ถ€๋‹ด์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ๋ผ๋„ MMS๋ฅผ ์ง€์–‘ํ•˜๊ณ  SMS๋ฅผ ์ง€ํ–ฅํ•œ๋‹ค.

     

    ๊ทธ๋ž˜์„œ ๊ฒ€์ƒ‰์„ ํ•ด๋ณด์•„๋„ ๋ชจ๋‘ ํ…์ŠคํŠธ๋งŒ ํ˜น์€ ์ด๋ฏธ์ง€๋งŒ ๋‹ด๊ธด ๋ฌธ์ž๋ฉ”์‹œ์ง€ ์ „์†ก ๋ฐฉ๋ฒ•๋งŒ์ด ๊ณต์œ ๋˜์–ด์žˆ์–ด

    ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ๋ฅผ ๋ชจ๋‘ ๋‹ด์€ ๋ฌธ์ž ์ „์†ก ๋ฐฉ๋ฒ•์„ ๊ตฌํ˜„ํ•˜๋Š”๋ฐ์— ์• ๋ฅผ ๋จน์—ˆ๋‹คใ…Ž

    ํ•ด๋‹น ๋ฐฉ๋ฒ•์€ ์ •ํ™•ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ  ๋ฐ”๋ž€๋‹ค...

     

     

     

     

     

    1. ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ implementation ํ•œ๋‹ค.

    ์ด๋ฏธ์ง€ ๋กœ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” Picasso, Glide, Coil ๋“ฑ์ด ์žˆ์ง€๋งŒ ์—ฌ๊ธฐ์„œ๋Š” Picasso๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

     

    buid.gradle

     //picasso
    implementation 'com.squareup.picasso:picasso:2.8'

     

     

    2. Manifest ๋‚ด๋ถ€์— file provider๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

     

    AndroidManifest.xml

    <provider
        android:authorities="${applicationId}.provider"
        android:name="androidx.core.content.FileProvider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            tools:replace="android:resource"
            android:resource="@xml/path" />
    </provider>

     

     

    3. ์œ„์˜ file provider์—์„œ ๊ฐ€์ ธ์˜ฌ file path๋ฅผ ์ •์˜ํ•  path.xml ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ค€๋‹ค.

     

    res/xml/path.xml ํŒŒ์ผ ์ƒ์„ฑ

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
        <external-files-path
            name="path"
            path="." />
    </paths>

     

     

    4. ๋ฌธ์ž ๋ฉ”์‹œ์ง€ ์ „์†ก ํ•จ์ˆ˜ ์ƒ์„ฑ

     

    private fun sharedSMS(title: String, desc: String, url: String) {
        try {
            val defaultSmsPackageName: String = Telephony.Sms.getDefaultSmsPackage(requireContext())
            Picasso.get().load(url).into(object : Target {
                override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
                    val sendIntent = Intent(Intent.ACTION_SEND)
    
                    sendIntent.type = "image/*"
                    sendIntent.putExtra(
                        "sms_body",
                        "$title \n" +
                        "$desc \n"+
                        url
                    )
                    sendIntent.putExtra(Intent.EXTRA_STREAM, getImage(bitmap))
                    sendIntent.setPackage(defaultSmsPackageName)
    
                    startActivity(sendIntent)
                }
    
                override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
    
                }
    
                override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
    
                }
    
            })
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

     

    Intent๋ฅผ ACTION_SEND๋กœ ์„ค์ •ํ•ด์ฃผ๊ณ , type์„ "image/*"์œผ๋กœ ์ง€์ •ํ•ด์ค€๋‹ค.

    putExtra์— sms_body๋ฅผ ์„ค์ •ํ•ด์ค€๋‹ค. ๊ด€๋ จ ๋‚ด์šฉ์˜ description, ๊ด€๋ จ url ๋“ฑ๋“ฑ์„ ๋„ฃ์–ด์ค€๋‹ค.

    ํ•ด๋‹น ๋‚ด์šฉ๊นŒ์ง€ ์ง„ํ–‰ํ•˜๋ฉด ์ด๋ฏธ์ง€ ์—†๋Š” SMS๊ฐ€ ์ „์†ก๋œ๋‹ค.

     

    ์ด๋ฏธ์ง€๋Š” putExtra๋ฅผ ์ด์šฉํ•ด Intent.EXTRA_STREAM์œผ๋กœ ์ด๋ฏธ์ง€ uri๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

     

     

     

    5. ์ด๋ฏธ์ง€ ๋กœ๋“œ ํ•จ์ˆ˜

    private fun getImage(bitmap: Bitmap?): Uri {
        var uri: Uri? = null
        try {
            val file = File(requireContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES), "bnk_sms.png")
            val outputStream = FileOutputStream(file)
    
            bitmap!!.compress(Bitmap.CompressFormat.PNG, 90, outputStream)
            outputStream.close()
            uri = FileProvider.getUriForFile(requireContext(), BuildConfig.APPLICATION_ID + ".provider", file)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    
        return uri!!
    }

     

     

    ์ด๋ฏธ์ง€๋ฅผ ๋ฉ”์‹œ์ง€๋กœ ๋ณด๋‚ด๊ธฐ ์œ„ํ•ด์„œ๋Š” ํด๋” ๋‚ด๋ถ€์— ์žˆ๋Š” ์ด๋ฏธ์ง€์—ฌ์•ผ ํ•œ๋‹ค.

    ๋”ฐ๋ผ์„œ FileProvider์— ์ง€์ •ํ•œ ํด๋”๋กœ ์ด๋ฏธ์ง€ ์ €์žฅ ํ›„ ์ด๋ฏธ์ง€์˜ uri๋ฅผ ์ด์šฉํ•ด ๋ฌธ์ž ๋ฉ”์‹œ์ง€๋กœ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

    ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•  ๋•Œ์—๋Š” ๋งค๋ฒˆ ๋ฉ”์‹œ์ง€ ๊ณต์œ ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋งˆ๋‹ค ์ด๋ฏธ์ง€๊ฐ€ ์ €์žฅ๋˜๋ฏ€๋กœ ์ €์žฅ๊ณต๊ฐ„ ๋‚ญ๋น„๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด ๊ฐ™์€ ์ด๋ฆ„์œผ๋กœ ์ €์žฅํ•˜์—ฌ override ๋˜๋„๋ก ํ–ˆ๋‹ค.

     

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.