• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    미해결

웹뷰에서 사이트로 넘어갈 때 오류가 납니다.

23.12.07 19:36 작성 조회수 124

0

package com.example.mango_content

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {
    //데이터 넣을 리스트 변수 생성
    private val items = mutableListOf<ContentsModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

//        리스트 데이터
//        데이터 클래스이기 때문에 차례대로 넣을 값만 넣어주면 된다
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/Quiver/shopPhotoList",
                "https://image.toast.com/aaaaaqx/rv/s4XU7ZHko4NjDEkULtFHbAA/231108173855775(0).jpeg",
                "퀴버(Quiver)"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/bistrogama/shopPhotoList?pickup-date=231207&pickup-time=0342",
                "https://image.toast.com/aaaaaqx/catchtable/shopinfo/s23522/23522_2221020170729696.jpg?detail750",
                "비스트로 가마"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/cucciolo_seoul/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0346",
                "https://ugc-images.catchtable.co.kr/rv/s7YDg2g4TxcuMPb-Eds2nKQ/4179dd6517aa48e1900c08e8c9c769a5",
                "쿠촐로 서울"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/schedule_seongsu/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0352",
                "https://ugc-images.catchtable.co.kr/rv/sXGZ4Ldt3lvBgj3V-4rxIsQ/e6ce38eef9ee412ca63da36dacabc57a",
                "스케줄 성수"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/Quiver/shopPhotoList",
                "https://image.toast.com/aaaaaqx/rv/s4XU7ZHko4NjDEkULtFHbAA/231108173855775(0).jpeg",
                "퀴버(Quiver)"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/bistrogama/shopPhotoList?pickup-date=231207&pickup-time=0342",
                "https://image.toast.com/aaaaaqx/catchtable/shopinfo/s23522/23522_2221020170729696.jpg?detail750",
                "비스트로 가마"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/cucciolo_seoul/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0346",
                "https://ugc-images.catchtable.co.kr/rv/s7YDg2g4TxcuMPb-Eds2nKQ/4179dd6517aa48e1900c08e8c9c769a5",
                "쿠촐로 서울"
            )
        )
        items.add(
            ContentsModel(
                "https://app.catchtable.co.kr/ct/shop/schedule_seongsu/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0352",
                "https://ugc-images.catchtable.co.kr/rv/sXGZ4Ldt3lvBgj3V-4rxIsQ/e6ce38eef9ee412ca63da36dacabc57a",
                "스케줄 성수"
            )
        )


        val recyclerview = findViewById<RecyclerView>(R.id.rv)
        val rvAdapter = RVAdapter(baseContext,items)
        recyclerview.adapter = rvAdapter

//        아이템 클릭 처리
        rvAdapter.itemClick = object : RVAdapter.ItemClick {
            override fun onClick(view: View, position: Int) {
                val intent = Intent(baseContext, ViewActivity::class.java)
                intent.putExtra("url", items[position].url )
                startActivity(intent)
            }
        }

        recyclerview.layoutManager = GridLayoutManager(this,2)
    }




}

MainActivity.kt

 

 

package com.example.mango_content

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.view.menu.MenuView.ItemView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide

//viewmodel을 받을 것임
class RVAdapter(val context: Context, val List: MutableList<ContentsModel>) : RecyclerView.Adapter<RVAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RVAdapter.ViewHolder {
        val v = LayoutInflater.from(parent.context).inflate(R.layout.rv_item, parent, false)
        return ViewHolder(v)
    }

//    웹뷰 클릭 이벤트 생성
    interface ItemClick {
        fun onClick(view : View, position: Int)
    }
    var itemClick : ItemClick? = null


    override fun onBindViewHolder(holder: RVAdapter.ViewHolder, position: Int) {
        if (itemClick != null) {
            holder.itemView.setOnClickListener {
                v -> itemClick!!.onClick(v, position)
            }
        }
        holder.bindItems(List[position])
    }

    override fun getItemCount(): Int {
        return List.size
    }


    inner class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
        fun bindItems(item : ContentsModel) {
            val rv_img = itemView.findViewById<ImageView>(R.id.rvImageArea)
            val rv_text = itemView.findViewById<TextView>(R.id.rvTextArea)

            rv_text.text = item.titleText
            Glide.with(context)
                .load(item.imageUrl)
                .into(rv_img)
        }

    }

}

RVAdapter.kt

 

package com.example.mango_content

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView

class ViewActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view)

        val webView = findViewById<WebView>(R.id.webView)
        webView.loadUrl(intent.getStringExtra("url").toString())
    }
}

ViewActivity.kt

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Mango_content"
        android:usesCleartextTraffic="true"
        tools:targetApi="31">
        <activity
            android:name=".ViewActivity"
            android:exported="false" />
        <activity
            android:name=".SplashActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true"></activity>
    </application>

</manifest>

manifest.xml

실행 했을 시, 다음과 같은 오류가 일어납니다.

스크린샷 2023-12-07 193440.png

망고플레이트가 서버 종료되어서 저는 캐치테이블 사이트를 이용하였습니다.

오류 구글링하여 매니패스트에

android:usesCleartextTraffic="true" 

도 추가 하였는데 그대로 오류나서 질문 드립니다. ㅠㅠ

답변 1

답변을 작성해보세요.

0

코드를 압축해서 깃허브/구글 드라이브를 통해서 공유해주시겠어요?

제가 한번 실행해보겠습니다.