Seize the day

POST : Android Dev Study

content://im/chat 분석

갤럭시S9플러스 OS10에서 테스트했고, 통신3사의 새로운 RCS기반 메시징 데이타임.  colum index, column name, value 순으로 출력했다.

READ_SMS 권한이 필요

contentResolver.query(
            Uri.parse("content://im/chat"),
            null,
            null,
            null,
            "date DESC")?.use { cursor ->
            val columnCount = cursor.columnCount

            if (cursor.moveToFirst()) {
                for(i in 0 until columnCount) {
                    Log.e("__T", "[$i=${cursor.getColumnName(i)}] ${cursor.getString(i)}")
                }
            }
        }

2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [0=_id] 80
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [1=thread_id] 7
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [2=transaction_id] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [3=address] 15884000
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [4=date_sent] 1633164482772
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [5=date] 1633164487845
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [6=read] 1
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [7=status] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [8=type] 1
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [9=body] {"messageHeader":"[Web발신]","copyAllowed":true,"zoomAllowed":true,"card":"open_rich_card","layout":{"background":"#ffffff","paddingLeft":"16dp","paddingRight":"16dp","widget":"LinearLayout","width":"284dp","height":"content","orientation":"vertical","children":[{"paddingTop":"16dp","marginBottom":"8dp","widget":"ImageView","width":"content","height":"content","mediaUrl":"https://content.maapconnect.com/files/proxy/bot/KT0000000006462?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlVHlwZSI6ImltYWdlL3BuZyIsIm9yaWdpbmFsVXJsIjoiaHR0cHM6Ly9tZWRpYS5oZXJtZXMua3QuY29tL2RhdGEvTUVESUEvbWVzc2FnZWJhc2UvMzA5MTc3MzQ0NmMzNDg1ZDk2YTM4Nzk1ZWM1MGIxYjkuTFQtMjAwODIxMTA0MzI3MjgxLUtRYnoucG5nIn0.FVrj1clsmNCnTvme0yrlg_YNeATkGKXn3n5QTP5Yy8f0LWPvc_0yTL2mqmS98lfFU088tWnQe9vIHZZjAsuf2zCAJrb45HyO-GUitymY-NU_NKYdcwPTQOaOc02vXOLkJO1HG2jtuclpbao9PDpMe8okc5M2LcE5UFgJGDEwdb157gYe-5xsVJMDlwVfPT9sGYtswdfQDoeCKiY-_eiQkfSTIMo9iamwUHwFUXzfBwBUd4d3J5vf9SdS8p61qI2pEWBBetrQ3lsqzfOczIUzrqe2SrECfdsj6MBHQE6pDzPLb8n24k8YKOrxxO4D1_NCWPgax_0SmTeY2LMYfsH4pg","mediaContentType":"image/png","mediaFileSize":4369},{"paddingBottom":"8dp","widget":"LinearLayout","width":"match","height":"content","orientation":"vertical","children":[{"paddingBottom":"8dp","visibility":"visible","widget":"LinearLayout","width":"match","height":"content","orientation":"horizontal","children":[{"weight":1,"widget":"TextView","width":"match","height":"content","text":"KB국민BC(8026) ","textAlignment":"textStart","textStyle":"bold","textColor":"#4483cf","textSize":"14dp"},{"weight":1,"widget":"TextView","width":"match","height":"content","text":"김*정 님","textAlignment":"textStart","textColor":"#404040","textSize":"14dp"}]},{"background":"#c0c0c0","marginBottom":"8dp","visibility":"visible","widget":"View","width":"match","height":"1dp"},{"paddingBottom":"8dp","visibility":"visible","widget":"LinearLayout","width":"match","height":"content","orientation":"horizontal","children":[{"weight":1,"widget":"TextView","width":"match","height":"content","text":"4,990원 승인","textAlignment":"textStart","textStyle":"bold","textColor":"#b91724","textSize":"18dp"},{"weight":1,"widget":"TextView","width":"match","height":"content","text":" 일시불 ","textAlignment":"textStart","textColor":"#404040","textSize":"14dp"}]},{"paddingBottom":"8dp","visibility":"visible","widget":"LinearLayout","width":"match","height":"content","orientation":"horizontal","children":[{"weight":1,"widget":"TextView","width":"match","height":"content","text":"10/02 17:48","textAlignment":"textStart","textColor":"#404040","textSize":"14dp"}]},{"paddingBottom":"8dp","visibility":"visible","widget":"LinearLayout","width":"match","height":"content","orientation":"horizontal","children":[{"weight":1,"widget":"TextView","width":"match","height":"content","text":"총누적","textAlignment":"textStart","textColor":"#404040","textSize":"14dp"},{"weight":1,"widget":"TextView","width":"match","height":"content","text":"329,412원","textAlignment":"textStart","textColor":"#404040","textSize":"14dp"}]},{"background":"#c0c0c0","marginBottom":"8dp","visibility":"visible","widget":"View","width":"match","height":"1dp"},{"paddingBottom":"8dp","visibility":"visible","widget":"LinearLayout","width":"match","height":"content","orientation":"horizontal","children":[{"weight":1,"widget":"TextView","width":"match","height":"content","text":"홈플러스 익스프레스","textAlignment":"textStart","textColor":"#404040","textSize":"14dp"}]}]}]},"suggestions":[{"action":{"displayText":"카드이용내역 확인(페이북앱)","urlAction":{"openUrl":{"url":"https://paybooc.co.kr/mobile/front/mapp/html/paybooc_app_download2.html"}},"postback":{"data":"set_by_chatbot_open_url"}}}]}
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [10=display_notification_status] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [11=seen] 1
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [12=message_type] 30
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [13=session_id] 90a654f25ea30d81d8bc493da0e9da77d7a4266d
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [14=content_type] application/vnd.gsma.openrichcard.v1.0+json
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [15=hidden] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [16=locked] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [17=displayed_counter] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [18=reserved] 0
2021-10-04 02:18:28.161 11666-11666/com.example.mms_test E/__T: [19=imdn_message_id] B01A0320211002174801811PmSiwp5AGBE6H
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [20=rcsdb_id] 81
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [21=user_alias] 
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [22=delivered_timestamp] 1633164487914
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [23=remote_uri] tel:+8215884000
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [24=service_type] 1
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [25=sim_slot] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [26=sim_imsi] 138724
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [27=recipients] 15884000
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [28=sticker_id] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [29=delivered_count] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [30=timedmsg_expiry] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [31=secret_mode] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [32=ext_info] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [33=app_id] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [34=msg_id] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [35=secret_message] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [36=mcloud_filename] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [37=favorite] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [38=using_mode] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [39=updated_timestamp] 1633164488739
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [40=from_address] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [41=device_name] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [42=safe_message] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [43=safe_image_path] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [44=spam_report] 0
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [45=creator] com.samsung.android.messaging
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [46=correlation_tag] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [47=object_id] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [48=cmc_prop] null
2021-10-04 02:18:28.162 11666-11666/com.example.mms_test E/__T: [49=is_bot] 1

 

body는 json으로 파싱하여 text를 얻을 수 있을 듯 하다. 안드로이드의 Native View의 속성을 그대로 json으로 구성했네.

{
  "messageHeader": "[Web발신]",
  "copyAllowed": true,
  "zoomAllowed": true,
  "card": "open_rich_card",
  "layout": {
    "background": "#ffffff",
    "paddingLeft": "16dp",
    "paddingRight": "16dp",
    "widget": "LinearLayout",
    "width": "284dp",
    "height": "content",
    "orientation": "vertical",
    "children": [
      {
        "paddingTop": "16dp",
        "marginBottom": "8dp",
        "widget": "ImageView",
        "width": "content",
        "height": "content",
        "mediaUrl": "https://content.maapconnect.com/files/proxy/bot/KT0000000006462?token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlVHlwZSI6ImltYWdlL3BuZyIsIm9yaWdpbmFsVXJsIjoiaHR0cHM6Ly9tZWRpYS5oZXJtZXMua3QuY29tL2RhdGEvTUVESUEvbWVzc2FnZWJhc2UvMzA5MTc3MzQ0NmMzNDg1ZDk2YTM4Nzk1ZWM1MGIxYjkuTFQtMjAwODIxMTA0MzI3MjgxLUtRYnoucG5nIn0.FVrj1clsmNCnTvme0yrlg_YNeATkGKXn3n5QTP5Yy8f0LWPvc_0yTL2mqmS98lfFU088tWnQe9vIHZZjAsuf2zCAJrb45HyO-GUitymY-NU_NKYdcwPTQOaOc02vXOLkJO1HG2jtuclpbao9PDpMe8okc5M2LcE5UFgJGDEwdb157gYe-5xsVJMDlwVfPT9sGYtswdfQDoeCKiY-_eiQkfSTIMo9iamwUHwFUXzfBwBUd4d3J5vf9SdS8p61qI2pEWBBetrQ3lsqzfOczIUzrqe2SrECfdsj6MBHQE6pDzPLb8n24k8YKOrxxO4D1_NCWPgax_0SmTeY2LMYfsH4pg",
        "mediaContentType": "image/png",
        "mediaFileSize": 4369
      },
      {
        "paddingBottom": "8dp",
        "widget": "LinearLayout",
        "width": "match",
        "height": "content",
        "orientation": "vertical",
        "children": [
          {
            "paddingBottom": "8dp",
            "visibility": "visible",
            "widget": "LinearLayout",
            "width": "match",
            "height": "content",
            "orientation": "horizontal",
            "children": [
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "KB국민BC(8026) ",
                "textAlignment": "textStart",
                "textStyle": "bold",
                "textColor": "#4483cf",
                "textSize": "14dp"
              },
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "김*정 님",
                "textAlignment": "textStart",
                "textColor": "#404040",
                "textSize": "14dp"
              }
            ]
          },
          {
            "background": "#c0c0c0",
            "marginBottom": "8dp",
            "visibility": "visible",
            "widget": "View",
            "width": "match",
            "height": "1dp"
          },
          {
            "paddingBottom": "8dp",
            "visibility": "visible",
            "widget": "LinearLayout",
            "width": "match",
            "height": "content",
            "orientation": "horizontal",
            "children": [
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "4,990원 승인",
                "textAlignment": "textStart",
                "textStyle": "bold",
                "textColor": "#b91724",
                "textSize": "18dp"
              },
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": " 일시불 ",
                "textAlignment": "textStart",
                "textColor": "#404040",
                "textSize": "14dp"
              }
            ]
          },
          {
            "paddingBottom": "8dp",
            "visibility": "visible",
            "widget": "LinearLayout",
            "width": "match",
            "height": "content",
            "orientation": "horizontal",
            "children": [
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "10/02 17:48",
                "textAlignment": "textStart",
                "textColor": "#404040",
                "textSize": "14dp"
              }
            ]
          },
          {
            "paddingBottom": "8dp",
            "visibility": "visible",
            "widget": "LinearLayout",
            "width": "match",
            "height": "content",
            "orientation": "horizontal",
            "children": [
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "총누적",
                "textAlignment": "textStart",
                "textColor": "#404040",
                "textSize": "14dp"
              },
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "329,412원",
                "textAlignment": "textStart",
                "textColor": "#404040",
                "textSize": "14dp"
              }
            ]
          },
          {
            "background": "#c0c0c0",
            "marginBottom": "8dp",
            "visibility": "visible",
            "widget": "View",
            "width": "match",
            "height": "1dp"
          },
          {
            "paddingBottom": "8dp",
            "visibility": "visible",
            "widget": "LinearLayout",
            "width": "match",
            "height": "content",
            "orientation": "horizontal",
            "children": [
              {
                "weight": 1,
                "widget": "TextView",
                "width": "match",
                "height": "content",
                "text": "홈플러스 익스프레스",
                "textAlignment": "textStart",
                "textColor": "#404040",
                "textSize": "14dp"
              }
            ]
          }
        ]
      }
    ]
  },
  "suggestions": [
    {
      "action": {
        "displayText": "카드이용내역 확인(페이북앱)",
        "urlAction": {
          "openUrl": {
            "url": "https://paybooc.co.kr/mobile/front/mapp/html/paybooc_app_download2.html"
          }
        },
        "postback": {
          "data": "set_by_chatbot_open_url"
        }
      }
    }
  ]
}

 

Json to text

    fun jsonTest() {
        val jsonObject = JSONObject(json)
        val layout = jsonObject.getJSONObject("layout")
        val text = when (layout.getString("widget")) {
            "LinearLayout" -> parseLinearLayout(layout)
            "TextView" -> layout.getString("text")
            else -> ""
        }
        Log.e("__T",  text)
    }

    private fun parseLinearLayout(widget: JSONObject): String {
        val sb = StringBuilder()
        val isVertical = widget.getString("orientation") == "vertical"
        val children = widget.getJSONArray("children")
        for(i in 0 until children.length()) {
            val widget = children.getJSONObject(i)
            val widgetName = widget.getString("widget")
            if (widgetName == "LinearLayout") {
                val text = parseLinearLayout(widget)
                sb.append(text)
                if (isVertical) sb.append("\n")
            } else if (widgetName == "TextView") {
                val text = widget.getString("text")
                sb.append(text)
                if (isVertical) sb.append("\n")
            }
        }
        return sb.toString()
    }

결과는 

KB국민BC(8026) 김*정 님
4,990원 승인 일시불 
10/02 17:48
총누적329,412원
홈플러스 익스프레스
top

posted at

2021. 10. 4. 02:30


CONTENTS

Seize the day
BLOG main image
김대정의 앱 개발 노트와 사는 이야기
RSS 2.0Tattertools
공지
아카이브
최근 글 최근 댓글
카테고리 태그 구름사이트 링크