I am a complete newbie to Kotlin and Android Studio but I have decided that I want to write an app for use at my work. I can write what I need in Excel and VB but unfortunately Macros are not supported on Android mobile devices, hence why I would like to write an app instead. I have worked out how to create pages (activities) and how to navigate back and forth between them (roughly), However, my ultimate goal is to capture the data that the user would enter into the text fields and then once they clicked the submit button it would then send the data they had entered via SMS to a predefined phone number (S) or alternatively as a text file to an email address. Any help would be greatly appreciated. Please let me know what you need me to post to enable any help Thanks in advance Code screenshot
package com.test.warehousecontrol
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.*
import androidx.core.app.ActivityCompat
import android.telephony.SmsManager
import kotlinx.android.synthetic.main.activity_second.*
class SecondActivity : AppCompatActivity()
{
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
// if(ActivityCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS)!=PackageManager.PERMISSION_GRANTED)
val backbut = findViewById<Button>(R.id.backbut)
backbut.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
private fun getSendSmsIntent(phoneNumber: String, content: String?): Intent? {
val uri = Uri.parse("smsto:$phoneNumber")
val intent: Intent = Intent(Intent.ACTION_SENDTO, uri)
intent.putExtra("sms_body", content)
return getIntent(Intent, true)
// return getIntent(intent, true)
val sub1: Button = findViewById<Button>(R.id.sub1)
sub1.setOnClickListener {
val cust: String = cust.text.toString()
val reg: String = reg.text.toString()
val pal: String = pal.text.toString()
val data: String =
"CUST : ".plus(cust).plus("\n").plus("REG : ").plus(reg).plus("\n").plus("PAL : ")
.plus(pal)
startActivity(getSendSmsIntent("1234567", data))
}
}
}