2 3madpk
2 3madpk
Aim of the practical: To design an android application Send SMS using Intent..
Objective:- The objective of an Android-based application that uses Intent to send SMS can be to create a
convenient and user-friendly tool for sending text messages. This type of app aims to leverage the Android
platform's capabilities to provide a seamless and efficient way for users to compose and send SMS messages.
JAVA CODE
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextMessage = findViewById(R.id.editTextMessage);
Button btnSendSMS = findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (checkPermission()) {
// Permission already granted, proceed with sending SMS
sendSMS();
} else {
// Request permission
requestPermission();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
}
});
}
if (smsIntent.resolveActivity(getPackageManager()) != null) {
startActivity(smsIntent);
} else {
Toast.makeText(this, "SMS app not found", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
// Permission granted, proceed with sending SMS
sendSMS();
} else {
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
}
}
}
}
XML:-
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your message"/>
<Button
android:id="@+id/btnSendSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextMessage"
android:layout_marginTop="16dp"
android:text="Send SMS" />
</RelativeLayout>
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
2. OUTPUT:
3. Learning Outcomes:
• Successful USE of your Android development environment.
• Project Workspace.
• Configuration button Completion.
• How to add new Intent.