final code
final code
This
version only sends an SMS when you click a button, and the phone number and message are
hardcoded for simplicity.
<uses-permission android:name="android.permission.SEND_SMS"/>
This is a very basic layout with a single button to send the SMS.
<Button
android:id="@+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS"
android:layout_centerInParent="true"/>
</RelativeLayout>
Step 3: MainActivity.java
This is the simple Java code to send an SMS when you click the button.
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
How It Works:
1. Hardcoded Phone Number: The phone number and message are hardcoded for
simplicity. You can change them as per your requirement.
2. Button Click: When you click the button, it calls the sendSMS() method to send an
SMS.
3. Toast Messages: A Toast message will show whether the SMS was successfully sent or
if it failed.
1. Run the App on a physical device (SMS won't work on an emulator without
configuration).
2. Click the Button: Press the "Send SMS" button, and the SMS will be sent to the
hardcoded number with the message.
This is as simple as it gets! If you want to add more features (like taking input from the user),
just let me know.
Here's an ultra-simple and basic example for Geocoding and Reverse Geocoding in Android.
This example uses the Geocoder class to convert an address into coordinates and vice versa.
This version is as minimal as possible, focused purely on the essentials.
Ensure you have permissions for using the internet and location:
This code does the Geocoding (Address to Coordinates) and Reverse Geocoding (Coordinates
to Address).
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
import java.util.List;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
editText = findViewById(R.id.editText);
resultText = findViewById(R.id.resultText);
Button btnGeocode = findViewById(R.id.btnGeocode);
Button btnReverseGeocode = findViewById(R.id.btnReverseGeocode);
// Initialize Geocoder
geocoder = new Geocoder(this);
How It Works:
Geocode: Enter an address like "New York" and click Geocode to see the coordinates
(latitude and longitude).
Reverse Geocode: Enter coordinates like "40.7128, -74.0060" and click Reverse
Geocode to see the address.
Key Points:
This is the simplest possible version of a Geocoding and Reverse Geocoding app!
Here’s a very basic and minimal example of using Bluetooth in Android — just to enable
Bluetooth and show a message if it's supported or not.
<Button
android:id="@+id/btnBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On Bluetooth" />
<TextView
android:id="@+id/txtStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status will appear here"
android:layout_marginTop="20dp"/>
</LinearLayout>
BluetoothAdapter bluetoothAdapter;
TextView txtStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtStatus = findViewById(R.id.txtStatus);
Button btnBluetooth = findViewById(R.id.btnBluetooth);
if (bluetoothAdapter == null) {
txtStatus.setText("Bluetooth not supported on this device.");
} else {
txtStatus.setText("Bluetooth supported.");
}
// Button click to enable Bluetooth
btnBluetooth.setOnClickListener(v -> {
if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBtIntent);
} else {
txtStatus.setText("Bluetooth is already ON");
}
});
}
}
Would you like the next step to include listing paired devices or scanning nearby ones?
Sure! Here's the most simple and basic example to just create a SQLite database and a table
in Android — no input, no buttons, just auto-creates when the app runs and shows a message.
✅ Goal:
Just create a database and one table when the app starts. Show a message like:
"Database and table created!"
<TextView
android:id="@+id/textMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Starting app..." />
</LinearLayout>
TextView textMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textMessage = findViewById(R.id.textMessage);
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE student (id INTEGER PRIMARY KEY, name
TEXT);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
// Not used here
}
}
}
Would you like to add inserting data or viewing it next, still in a very simple way?
This should give you a complete, simple Android app that demonstrates both Geocoding and
Reverse Geocoding.
Here's a simple Android Text to Speech (TTS) app based on the layout in your image that
speaks the word "thanks" when a button is clicked.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Text to Speech (TTS)\nDemo"
android:textSize="18sp"
android:textAlignment="center"
android:layout_marginBottom="20dp"/>
<EditText
android:id="@+id/editTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="thanks"
android:hint="Enter text"
android:gravity="center"
android:layout_marginBottom="20dp" />
<Button
android:id="@+id/btnSpeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLICK TO CONVERT TEXT TO SPEECH" />
</LinearLayout>
TextToSpeech tts;
EditText editText;
Button btnSpeak;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editTextInput);
btnSpeak = findViewById(R.id.btnSpeak);
// Initialize TextToSpeech
tts = new TextToSpeech(this, status -> {
if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.US); // Set language to US English
}
});
btnSpeak.setOnClickListener(v -> {
String text = editText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
});
}
@Override
protected void onDestroy() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
}
Here's a simple full example of a Toast message in Android using Java with a Button:
✅ Step-by-Step Example
<Button
android:id="@+id/showToastButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast" />
</LinearLayout>
2. MainActivity.java
package com.example.toastdemo;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showToastButton.setOnClickListener(v -> {
Toast.makeText(this, "Welcome!", Toast.LENGTH_SHORT).show();
});
}
}
🧱 What Happens?
When you click the "Show Toast" button, a small popup message (Toast) appears saying:
"This is a toast message!"