<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone number"
android:inputType="phone"/>
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter message"
android:inputType="textMultiLine"/>
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS"/>
</LinearLayout>
package com.example.smsb;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText etPhone, etMessage;
Button btnSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etPhone = findViewById(R.id.etPhone);
etMessage = findViewById(R.id.etMessage);
btnSend = findViewById(R.id.btnSend);
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phone = etPhone.getText().toString();
String message = etMessage.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phone, null, message, null, null);
Toast.makeText(MainActivity.this,
"Message Sent",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this,
"Message Not Sent",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
<uses-permission android:name="android.permission.SEND_SMS"/>
Whether you are struggling to balance three-phase power equations or designing a stable feedback control system, seeking professional electrical engineering assignment help can provide the clarity needed to master these high-level concepts. Having an expert guide you through the application of Kirchhoff’s laws or the nuances of semiconductor physics doesn't just help with grades—it builds the technical confidence required for real-world innovation. This is an essential read for any student looking to turn theoretical "sparks" into functional engineering solutions!
ReplyDelete