Skip to content

Commit

Permalink
适配安卓4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
miaozilong committed Mar 1, 2022
1 parent 917df0f commit b2fab95
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdkVersion 30
defaultConfig {
applicationId "com.ester.remotetrigger"
minSdkVersion 29
minSdkVersion 18
targetSdkVersion 30
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -47,6 +47,6 @@ dependencies {
implementation "com.squareup.retrofit2:converter-gson:2.3.0"
implementation 'io.reactivex:rxandroid:1.2.1'

implementation 'com.sun.mail:android-mail:1.6.2'
implementation 'com.sun.mail:android-activation:1.6.2'
implementation 'com.sun.mail:android-mail:1.5.5'
implementation 'com.sun.mail:android-activation:1.5.5'
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class MainActivity : AppCompatActivity() {

btStop.text = "启动服务"
} else {
startForegroundService(startServiceIntent)
// 18 26
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// startForegroundService(startServiceIntent)
// }
startService(Intent(this, ForwardSMSService::class.java))
trigger_text.text = "事件监听中……"

btStop.text = "停止服务"
Expand Down Expand Up @@ -89,7 +93,9 @@ class MainActivity : AppCompatActivity() {
}

if (needPermissions) {
requestPermissions(permissions, REQUEST_CODE)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(permissions, REQUEST_CODE)
}
}
}

Expand Down
35 changes: 19 additions & 16 deletions app/src/main/java/com/ester/remotetrigger/service/ForwardService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ForwardService(context: Context) {
this.context = context
}

fun Send(text:String, desp:String) {
fun Send(text: String, desp: String) {
val sp = PreferenceManager.getDefaultSharedPreferences(context)

if (sp.getBoolean("send.ftqq", false)) {
Expand All @@ -54,7 +54,7 @@ class ForwardService(context: Context) {
}
}

fun SendEmail(text:String, desp:String, sp:SharedPreferences) {
fun SendEmail(text: String, desp: String, sp: SharedPreferences) {
Log.d(LOG_TAG, "Notify send email")

Thread {
Expand All @@ -64,31 +64,31 @@ class ForwardService(context: Context) {

val session: Session = Session.getInstance(properties)
val message: Message = MimeMessage(session)
val me:String? = sp.getString("settings.smtp_user", "")
val to:String? = sp.getString("settings.smtp_receive", "")
val host:String? = sp.getString("settings.smtp_host", "")
val user:String? = sp.getString("settings.smtp_user", "")
val pwd:String? = sp.getString("settings.smtp_pwd", "")
val me: String? = sp.getString("settings.smtp_user", "")
val to: String? = sp.getString("settings.smtp_receive", "")
val host: String? = sp.getString("settings.smtp_host", "")
val user: String? = sp.getString("settings.smtp_user", "")
val pwd: String? = sp.getString("settings.smtp_pwd", "")

message.subject = "$text【转发提醒】"
message.subject = "$text"
message.setText(desp)
message.setFrom(InternetAddress(me))
message.addRecipients(Message.RecipientType.TO, arrayOf<Address>(InternetAddress(to)))
message.saveChanges()

val transport: Transport = session.getTransport()
transport.connect(
host,
25,
user,
pwd)
host,
587,
user,
pwd
)
transport.sendMessage(message, message.allRecipients)

transport.close()
}.start()
}

fun SendFTQQ(text:String, desp:String, sp:SharedPreferences) {
fun SendFTQQ(text: String, desp: String, sp: SharedPreferences) {
Log.d(LOG_TAG, "Notify send ftqq")

val apiService = FTQQApiService.create()
Expand All @@ -107,7 +107,7 @@ class ForwardService(context: Context) {
})
}

fun SendBark(text:String, desp:String, sp:SharedPreferences) {
fun SendBark(text: String, desp: String, sp: SharedPreferences) {
Log.d(LOG_TAG, "Notify send bark")

val apiService = BarkApiService.create()
Expand All @@ -116,7 +116,10 @@ class ForwardService(context: Context) {
if (key != null) {
val call = apiService.sendNotify(key, text, desp)
call.enqueue(object : Callback<BarkNotifyResult> {
override fun onResponse(call: Call<BarkNotifyResult>?, response: Response<BarkNotifyResult>?) {
override fun onResponse(
call: Call<BarkNotifyResult>?,
response: Response<BarkNotifyResult>?
) {
if (response?.code() == 200) {
Log.d(LOG_TAG, "Tel Bark Notify sent ${response.body()?.code}")
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ester.remotetrigger

import com.ester.remotetrigger.service.ForwardService
import org.junit.Test

import org.junit.Assert.*
Expand Down

0 comments on commit b2fab95

Please sign in to comment.