Skip to content

Commit 9947e14

Browse files
author
srthk
committed
fix layout and add ServiceBinding.kt
1 parent a87faf3 commit 9947e14

File tree

8 files changed

+49
-12
lines changed

8 files changed

+49
-12
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package srthk.pthk.smsforwarder.services
2+
3+
import android.app.Service
4+
import android.content.Intent
5+
import android.os.IBinder
6+
import android.widget.Toast
7+
8+
class ServiceBinding : Service() {
9+
override fun onBind(p0: Intent?): IBinder? {
10+
TODO("Not yet implemented")
11+
}
12+
13+
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
14+
onTaskRemoved(intent);
15+
Toast.makeText(
16+
applicationContext, "This is a Service running in Background",
17+
Toast.LENGTH_SHORT
18+
).show();
19+
return START_STICKY;
20+
}
21+
22+
override fun onTaskRemoved(rootIntent: Intent?) {
23+
val restartServiceIntent = Intent(applicationContext, this.javaClass)
24+
restartServiceIntent.setPackage(packageName)
25+
startService(restartServiceIntent)
26+
super.onTaskRemoved(rootIntent)
27+
}
28+
}

app/src/main/java/srthk/pthk/smsforwarder/services/SmsListener.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package srthk.pthk.smsforwarder.services
22

3+
import android.app.Service
34
import android.content.BroadcastReceiver
45
import android.content.Context
56
import android.content.Intent
7+
import android.os.IBinder
68
import android.provider.Telephony
79
import android.telephony.SmsManager
810
import android.telephony.SmsMessage

app/src/main/java/srthk/pthk/smsforwarder/ui/MainActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package srthk.pthk.smsforwarder.ui
22

33
import android.Manifest
44
import android.content.Context
5+
import android.content.Intent
56
import android.content.SharedPreferences
67
import android.os.Bundle
78
import android.text.Editable
89
import android.text.TextWatcher
910
import androidx.appcompat.app.AppCompatActivity
1011
import kotlinx.android.synthetic.main.activity_main.*
1112
import srthk.pthk.smsforwarder.R
13+
import srthk.pthk.smsforwarder.services.ServiceBinding
1214

1315

1416
class MainActivity : AppCompatActivity() {
@@ -32,6 +34,7 @@ class MainActivity : AppCompatActivity() {
3234
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
3335
override fun afterTextChanged(s: Editable) {
3436
sharedPreferences.edit().putString("phoneNumber", s.toString()).apply()
37+
startService(Intent(applicationContext, ServiceBinding::class.java))
3538
}
3639
})
3740
}

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99

1010

1111
<TextView
12-
android:text="Enter the Number here to which you want to forward the sms you recieve"
13-
android:layout_width="374dp"
12+
android:text="@string/enter_the_number_here_to_which_you_want_to_forward_the_sms_you_recieve"
13+
android:layout_width="0dp"
1414
android:layout_height="103dp" android:id="@+id/textView"
1515
android:textSize="25sp"
1616
app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
17-
android:layout_marginEnd="16dp" app:layout_constraintStart_toStartOf="parent"
18-
android:layout_marginStart="16dp" android:layout_marginTop="76dp"
19-
app:layout_constraintHorizontal_bias="0.0"/>
17+
android:layout_marginEnd="24dp" app:layout_constraintStart_toStartOf="parent"
18+
android:layout_marginStart="24dp" android:layout_marginTop="76dp"
19+
/>
2020
<EditText
21-
android:layout_width="376dp"
21+
android:layout_width="0dp"
2222
android:layout_height="61dp"
2323
android:inputType="phone"
2424
android:ems="10"
2525
android:id="@+id/phoneNumberInput"
2626
app:layout_constraintStart_toStartOf="parent"
27-
android:layout_marginStart="16dp" app:layout_constraintEnd_toEndOf="parent"
28-
android:layout_marginEnd="16dp" app:layout_constraintBottom_toBottomOf="parent"
27+
android:layout_marginStart="24dp" app:layout_constraintEnd_toEndOf="parent"
28+
android:layout_marginEnd="24dp" app:layout_constraintBottom_toBottomOf="parent"
2929
app:layout_constraintTop_toBottomOf="@+id/textView" app:layout_constraintHorizontal_bias="0.0"
30-
app:layout_constraintVertical_bias="0.032"/>
30+
app:layout_constraintVertical_bias="0.032" android:autofillHints="Phone number"/>
3131
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<resources>
22
<string name="app_name">Sms Forwarder</string>
3+
<string name="enter_the_number_here_to_which_you_want_to_forward_the_sms_you_recieve">Enter the Number here to which
4+
you want to forward the sms you recieve
5+
</string>
36
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.6.0-rc01'
11+
classpath 'com.android.tools.build:gradle:4.0.0'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313

1414
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Jul 07 22:30:53 IST 2020
1+
#Mon May 08 16:59:23 IST 2023
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)