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"
}
}