Skip to content

Commit

Permalink
fix layout and add ServiceBinding.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
srthk committed May 8, 2023
1 parent a87faf3 commit 9947e14
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package srthk.pthk.smsforwarder.services

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.widget.Toast

class ServiceBinding : Service() {
override fun onBind(p0: Intent?): IBinder? {
TODO("Not yet implemented")
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
onTaskRemoved(intent);
Toast.makeText(
applicationContext, "This is a Service running in Background",
Toast.LENGTH_SHORT
).show();
return START_STICKY;
}

override fun onTaskRemoved(rootIntent: Intent?) {
val restartServiceIntent = Intent(applicationContext, this.javaClass)
restartServiceIntent.setPackage(packageName)
startService(restartServiceIntent)
super.onTaskRemoved(rootIntent)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package srthk.pthk.smsforwarder.services

import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.provider.Telephony
import android.telephony.SmsManager
import android.telephony.SmsMessage
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/srthk/pthk/smsforwarder/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package srthk.pthk.smsforwarder.ui

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import srthk.pthk.smsforwarder.R
import srthk.pthk.smsforwarder.services.ServiceBinding


class MainActivity : AppCompatActivity() {
Expand All @@ -32,6 +34,7 @@ class MainActivity : AppCompatActivity() {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable) {
sharedPreferences.edit().putString("phoneNumber", s.toString()).apply()
startService(Intent(applicationContext, ServiceBinding::class.java))
}
})
}
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@


<TextView
android:text="Enter the Number here to which you want to forward the sms you recieve"
android:layout_width="374dp"
android:text="@string/enter_the_number_here_to_which_you_want_to_forward_the_sms_you_recieve"
android:layout_width="0dp"
android:layout_height="103dp" android:id="@+id/textView"
android:textSize="25sp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp" android:layout_marginTop="76dp"
app:layout_constraintHorizontal_bias="0.0"/>
android:layout_marginEnd="24dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="24dp" android:layout_marginTop="76dp"
/>
<EditText
android:layout_width="376dp"
android:layout_width="0dp"
android:layout_height="61dp"
android:inputType="phone"
android:ems="10"
android:id="@+id/phoneNumberInput"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="24dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="24dp" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.032"/>
app:layout_constraintVertical_bias="0.032" android:autofillHints="Phone number"/>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">Sms Forwarder</string>
<string name="enter_the_number_here_to_which_you_want_to_forward_the_sms_you_recieve">Enter the Number here to which
you want to forward the sms you recieve
</string>
</resources>
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 {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0-rc01'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

0 comments on commit 9947e14

Please sign in to comment.