admin管理员组文章数量:1332361
pink screen in touchable areas problem in running HTML 5 game in android webview
- game in assets folder
- local server starts.
- shows pink screen in webview and also in external browser in chrome
I think the problem is with the making the server side files the code is
how to solve the issue?class LocalServer(private val context: MainActivity, port: Int) : NanoHTTPD(port) {
override fun serve(session: IHTTPSession): Response {
return try {
var uri = session.uri
if (uri == "/") uri = "/index.html" // Default to index.html if root is accessed
// Log the file path for debugging
Log.d("LocalServer", "Accessing file: game$uri")
val filePath = "game$uri" // Correct the path to look for files in the 'game' folder inside assets
// Check if the file exists in assets
val inputStream: InputStream = context.assets.open(filePath)
val buffer = ByteArray(inputStream.available())
inputStream.read(buffer)
inputStream.close()
// Log successful file access
Log.d("LocalServer", "Successfully served: $filePath")
newFixedLengthResponse(Response.Status.OK, getMimeType(uri), String(buffer))
} catch (e: IOException) {
Log.e("LocalServer", "File not found: ${e.message}")
newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "404 Not Found")
}
}
private fun getMimeType(uri: String): String {
return when {
uri.endsWith(".html") -> "text/html"
uri.endsWith(".js") -> "application/javascript"
uri.endsWith(".css") -> "text/css"
uri.endsWith(".png") -> "image/png"
uri.endsWith(".jpg") -> "image/jpeg"
uri.endsWith(".gif") -> "image/gif"
else -> "application/octet-stream"
}
}
本文标签: kotlinpink screen in touchable areas problem in running HTML 5 game in android webviewStack Overflow
版权声明:本文标题:kotlin - pink screen in touchable areas problem in running HTML 5 game in android webview - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315675a2451767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论