Ben Edwards
09/11/2022, 2:26 PM@file:Suppress("DEPRECATION")
package com.funkytwig.flickerbrowser
import android.os.AsyncTask
import android.util.Log
import java.io.IOException
import java.net.MalformedURLException
import java.net.URL
enum class DowsloadStatus {
OK, IDLE, NOT_INSTALLED, FAILED_OR_EMPTY, PERMISSIONS_ERROR, ERROR
}
private const val TAG = "GetRawData"
@Suppress("DEPRECATION")
class GetRawData : AsyncTask<String, Void, String>() { // class
private var downloadStatus = DowsloadStatus.IDLE
@Deprecated("Deprecated in Java")
override fun doInBackground(vararg params: String?): String {
// params[0] = JSON URL
val funct = "doInBackground"
Log.d(TAG, funct)
Log.d(TAG, "$funct ${params[0]}")
if (params[0] == null) {
Log.d(TAG, "$funct No URL")
downloadStatus = DowsloadStatus.NOT_INSTALLED
return "No URL Specified"
}
try {
downloadStatus = DowsloadStatus.OK
Log.d(TAG, "$funct: DowsloadStatus.OK")
return URL(params[0]).readText()
} catch (e: Exception) {
val errorMessage = when (e) {
is MalformedURLException -> {
downloadStatus = DowsloadStatus.NOT_INSTALLED
"Invalid URL ${e.message}"
}
is IOException -> {
downloadStatus = DowsloadStatus.FAILED_OR_EMPTY
"IO Exception ${e.message}"
}
is SecurityException -> {
downloadStatus = DowsloadStatus.PERMISSIONS_ERROR
"Needs Permission ${e.message}"
}
else -> {
downloadStatus = DowsloadStatus.ERROR
"Unknown Error ${e.message}"
}
}
Log.d(TAG, "$funct dome errorMessage")
return errorMessage
} // try/catch
} // doInBackground
@Deprecated("Deprecated in Java")
override fun onPostExecute(result: String?) {
val funct = "onPostExecute"
Log.d(TAG, funct)
super.onPostExecute(result)
}
@Deprecated("Deprecated in Java")
override fun onCancelled() {
val funct = "onCancelled"
Log.d(TAG, funct)
super.onCancelled()
}
@Deprecated("Deprecated in Java")
override fun onPreExecute() {
val funct = "onPreExecute"
Log.d(TAG, funct)
super.onPreExecute()
}
@Deprecated("Deprecated in Java")
override fun onProgressUpdate(vararg values: Void?) {
val funct = "onProgressUpdate"
Log.d(TAG, funct)
super.onProgressUpdate(*values)
}
}
Any ideas?Mustafa Ozhan
09/11/2022, 2:59 PMBen Edwards
09/11/2022, 7:22 PMreturn URL(params[0]).readText()
which is the line discovered is where the problem is. I did some running in debug and when it runs that line it hangs. I tried with a real phone and it works.
Is there a particular phone SDSK I should use?Mustafa Ozhan
09/13/2022, 11:25 AM