Skip to content

Instantly share code, notes, and snippets.

View hissain's full-sized avatar
:atom:

Md. Sazzad Hissain Khan hissain

:atom:
View GitHub Profile
val json1 = """
{
"name": "Mark",
"address": "London":
}"""
val student = Gson().fromJson(json1, Student::class.java)
val student = Student("Alex", "Rome, 1500") // instance
val jsonString = Gson().toJson(student) // json string
data class Student (
var name: String? = null,
var address: String? = null) {
}
val student = Student("Alex", "Rome") // instance
dependencies {
...
implementation 'com.google.code.gson:gson:2.8.5'
...
}
private fun loadWebView(){
val loader = Thread {
when {
MyReachability.hasServerConnected(this) -> runOnUiThread {
hideLoadingDialog()
Log.d(classTag, "Loading ${Constants.LANDING_SERVER}")
mWebView.loadUrl(Constants.LANDING_SERVER)
}
MyReachability.hasInternetConnected(this) -> runOnUiThread {
object MyReachability {
private fun hasNetworkAvailable(context: Context): Boolean {
val service = Context.CONNECTIVITY_SERVICE
val manager = context.getSystemService(service) as ConnectivityManager?
val network = manager?.activeNetworkInfo
Log.d(classTag, "hasNetworkAvailable: ${(network != null)}")
return (network?.isConnected) ?: false
}
//Constants.LANDING_SERVER = "https://www.myserver.com"
fun hasServerConnected(context: Context): Boolean {
if (hasNetworkAvailable(context)) {
try {
val connection = URL(Constants.LANDING_SERVER).openConnection() as HttpURLConnection
connection.setRequestProperty("User-Agent", "Test")
connection.setRequestProperty("Connection", "close")
connection.connectTimeout = 1000 //configurable
connection.connect()
Logger.d(classTag, "hasServerConnected: ${(connection.responseCode == 200)}")
//Constants.REACHABILITY_SERVER = "https://www.google.com"
fun hasInternetConnected(context: Context): Boolean {
if (hasNetworkAvailable(context)) {
try {
val connection = URL(Constants.REACHABILITY_SERVER).openConnection() as HttpURLConnection
connection.setRequestProperty("User-Agent", "ConnectionTest")
connection.setRequestProperty("Connection", "close")
connection.connectTimeout = 1000 // configurable
connection.connect()
Logger.d(classTag, "hasInternetConnected: ${(connection.responseCode == 200)}")
private fun hasNetworkAvailable(context: Context): Boolean {
val service = Context.CONNECTIVITY_SERVICE
val manager = context.getSystemService(service) as ConnectivityManager?
val network = manager?.activeNetworkInfo
Logger.d(classTag, "hasNetworkAvailable: ${(network != null)}")
return (network != null)
}
set recipientName to "Hissain Khan"
set recipientAddress to "hissain.khan@gmail.com"
set theSubject to "AppleScript Automated Email Sending"
set theContent to "This email was sent using AppleScript! for testing"
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
send
end tell