Skip to content

Commit

Permalink
Toast on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Jul 23, 2021
1 parent 874de90 commit b4075c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId "org.traccar.gateway"
minSdkVersion 21
targetSdkVersion 29
versionCode 6
versionName "4.0"
versionCode 7
versionName "4.1"
setProperty("archivesBaseName", "traccar-v${versionName}")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.moez.QKSMS.feature.gateway

import android.annotation.SuppressLint
import android.os.Handler
import android.os.Looper
import android.telephony.SmsManager
import android.widget.Toast
import com.google.firebase.messaging.FirebaseMessagingService
Expand All @@ -9,14 +11,18 @@ import com.google.firebase.messaging.RemoteMessage
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
class GatewayMessagingService : FirebaseMessagingService() {

private val handler = Handler(Looper.getMainLooper())

override fun onMessageReceived(remoteMessage: RemoteMessage) {
val phone = remoteMessage.data["phone"]
val message = remoteMessage.data["message"]
if (phone != null && message != null) {
try {
SmsManager.getDefault().sendTextMessage(phone, null, message, null, null)
} catch (e: Exception) {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
handler.post {
Toast.makeText(this, e.message, Toast.LENGTH_LONG).show()
}
}
}
}
Expand Down

0 comments on commit b4075c9

Please sign in to comment.