Skip to content

Commit

Permalink
Merge pull request #12 from airrobe/hotfix
Browse files Browse the repository at this point in the history
Hotfix for internet connection issues
  • Loading branch information
creative-dev-lab authored Apr 13, 2022
2 parents 043e1b8 + 429ea62 commit 81b5a86
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
Binary file modified AirRobeWidget/releases/AirRobeWidget-1.0.1.aar
Binary file not shown.
1 change: 1 addition & 0 deletions AirRobeWidget/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.airrobe.widgetsdk.airrobewidget">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.airrobe.widgetsdk.airrobewidget.service

import com.airrobe.widgetsdk.airrobewidget.BuildConfig
import org.json.JSONObject
import java.io.*
import java.lang.Exception
Expand All @@ -12,24 +11,25 @@ import javax.net.ssl.HttpsURLConnection
internal object AirRobeApiService {
const val GET: String = "GET"
const val POST: String = "POST"
private val userHeaderString: String = "airrobeWidget/${BuildConfig.VERSION_NAME} (Android ${android.os.Build.VERSION.RELEASE})"
private val userHeaderString: String = "airrobeWidget/Android ${android.os.Build.VERSION.RELEASE}"

fun requestPOST(r_url: String?, postDataParams: JSONObject): String? {
val url = URL(r_url)
val urlConnection: HttpURLConnection = url.openConnection() as HttpURLConnection
urlConnection.setRequestProperty("User-Agent", userHeaderString)
urlConnection.readTimeout = 3000
urlConnection.connectTimeout = 3000
urlConnection.requestMethod = POST
urlConnection.doInput = true
urlConnection.doOutput = true
val os: OutputStream = urlConnection.outputStream
val writer = BufferedWriter(OutputStreamWriter(os, "UTF-8"))
writer.write(encodeParams(postDataParams))
writer.flush()
writer.close()
os.close()
return try {
val urlConnection: HttpURLConnection = url.openConnection() as HttpURLConnection
urlConnection.setRequestProperty("User-Agent", userHeaderString)
urlConnection.readTimeout = 3000
urlConnection.connectTimeout = 3000
urlConnection.requestMethod = POST
urlConnection.doInput = true
urlConnection.doOutput = true
val os: OutputStream = urlConnection.outputStream
val writer = BufferedWriter(OutputStreamWriter(os, "UTF-8"))
writer.write(encodeParams(postDataParams))
writer.flush()
writer.close()
os.close()

val responseCode: Int = urlConnection.responseCode // To Check for 200
if (responseCode == HttpsURLConnection.HTTP_OK) {
val `in` = BufferedReader(InputStreamReader(urlConnection.inputStream))
Expand All @@ -42,16 +42,17 @@ internal object AirRobeApiService {
`in`.close()
sb.toString()
} else null
} catch (e: IOException) {
} catch (e: Exception) {
return null
}
}

fun requestGET(url: String?): String? {
val obj = URL(url)
val urlConnection = obj.openConnection() as HttpURLConnection
urlConnection.requestMethod = GET
return try {
val urlConnection = obj.openConnection() as HttpURLConnection
urlConnection.requestMethod = GET

val responseCode = urlConnection.responseCode
if (responseCode == HttpURLConnection.HTTP_OK) {
val `in` = BufferedReader(InputStreamReader(urlConnection.inputStream))
Expand All @@ -63,7 +64,7 @@ internal object AirRobeApiService {
`in`.close()
response.toString()
} else null
} catch (e: IOException) {
} catch (e: Exception) {
null
}
}
Expand All @@ -86,4 +87,4 @@ internal object AirRobeApiService {
null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ class AirRobeMultiOptIn @JvmOverloads constructor(
Log.d(TAG, "Category is not eligible")
}
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_gradle_plugin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Binary file modified demo/libs/AirRobeWidget.aar
Binary file not shown.

0 comments on commit 81b5a86

Please sign in to comment.