0% found this document useful (0 votes)
9 views3 pages

SMS Sending App for Android

The document contains XML code for an AndroidManifest file and activity layout file that define an SMS sending app, as well as Java code for a MainActivity class that implements the SMS sending functionality.

Uploaded by

Ritesh Kolate
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

SMS Sending App for Android

The document contains XML code for an AndroidManifest file and activity layout file that define an SMS sending app, as well as Java code for a MainActivity class that implements the SMS sending functionality.

Uploaded by

Ritesh Kolate
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link] AndroidManifest.

xml

<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>


<LinearLayout <manifest
xmlns:android="[Link] xmlns:android="[Link]
android" xmlns:tools="[Link]
xmlns:app="[Link] package="[Link].smspractical29">
auto"
xmlns:tools="[Link] <!-- Add the permission for sending SMS -->
android:layout_width="match_parent" <uses-feature
android:layout_height="match_parent" android:name="[Link]"
android:orientation="vertical" android:required="false" />
android:padding="16dp" <uses-permission
android:gravity="center_horizontal" android:name="[Link].SEND_SMS" />
tools:context=".MainActivity">
<application
<EditText android:allowBackup="true"
android:id="@+id/et_phone" android:dataExtractionRules="@xml/data_extraction_rules"
android:layout_width="match_parent" android:fullBackupContent="@xml/backup_rules"
android:layout_height="wrap_content" android:icon="@mipmap/ic_launcher"
android:hint="Enter Phone Number" android:label="@string/app_name"
android:padding="12dp" android:roundIcon="@mipmap/ic_launcher_round"
android:maxLength="10" android:supportsRtl="true"
android:inputType="phone" android:theme="@style/Theme.SMSPRACTICAL29"
/> tools:targetApi="31">
<EditText <activity
android:id="@+id/et_message" android:name=".MainActivity"
android:layout_width="match_parent" android:exported="true">
android:layout_height="wrap_content" <intent-filter>
android:hint="Enter Message" <action android:name="[Link]" />
android:padding="12dp"
android:minLines="6" <category
android:inputType="textMultiLine" android:name="[Link]" />
android:gravity="top" </intent-filter>
android:layout_marginTop="8dp"/> </activity>
<Button </application>
android:id="@+id/bt_send"
android:layout_width="wrap_content" </manifest>
android:layout_height="wrap_content"
android:text="Send SMS"
android:layout_marginTop="32dp"/>
</LinearLayout>
[Link]
package [Link].smspractical29;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText etPhone, etMessage;


Button btSend;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

etPhone = findViewById([Link].et_phone);
etMessage = findViewById([Link].et_message);
btSend = findViewById([Link].bt_send);

[Link](new [Link]() {
@Override
public void onClick(View view) {
if ([Link]([Link],
[Link].SEND_SMS) == PackageManager.PERMISSION_GRANTED) {
sendMessage();
} else {
[Link]([Link], new
String[]{[Link].SEND_SMS}, 100);
}
}
});
}

private void sendMessage() {


String sPhone = [Link]().toString().trim();
String sMessage = [Link]().toString().trim();
if (![Link]("") && ![Link]("")) {
SmsManager smsManager = [Link]();
[Link](sPhone, null, sMessage, null, null);
[Link](getApplicationContext(), "SMS sent successfully!",
Toast.LENGTH_SHORT).show();
} else {
[Link](getApplicationContext(), "Enter value first.",
Toast.LENGTH_SHORT).show();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
[Link](requestCode, permissions, grantResults);

if (requestCode == 100 && [Link] > 0 && grantResults[0] ==


PackageManager.PERMISSION_GRANTED) {
sendMessage();
} else {
[Link](getApplicationContext(), "Permission Denied!",
Toast.LENGTH_SHORT).show();
}
}
}

You might also like