AndroidManifest.
xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
xmlns:tools="[Link]
<uses-permission android:name="[Link].SEND_SMS" />
<uses-permission android:name="[Link].READ_SMS"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Q1"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
<meta-data
android:name="[Link].lib_name"
android:value="" />
</activity>
<activity android:name=".receive_sms" />
</application>
</manifest>
sms_receive.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:paddingTop="15dp"
android:text="SMS From:\n"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:paddingTop="15dp"
android:id="@+id/show_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
[Link]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SMS Inbox"/>
<ListView
android:id ="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone Number"
android:textAllCaps="false"
/>
<EditText
android:id="@+id/phn_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMS Message"
android:textAllCaps="false"
/>
<EditText
android:id = "@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<Button
android:id="@+id/sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS"
android:textAllCaps="false"/>
</LinearLayout>
receive_sms.java
package [Link].q1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class receive_sms extends Activity {
Uri sms_uri = [Link]("content://sms/inbox");
ListView lv;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link]);
lv = findViewById([Link]);
Cursor c = getContentResolver().query(sms_uri,null,null,null,null);
String[] msgData = new String[[Link]()];
while([Link]())
{
int index = [Link]("body");
msgData[[Link]()] = [Link](index);
}
ArrayAdapter<String> adapter = new
ArrayAdapter<>(getApplication(),[Link].sms_receive,[Link].show_sms,msgData);
[Link](adapter);
[Link]();
}
}
[Link]
package [Link].q1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText phn_no,message;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
phn_no = findViewById([Link].phn_no);
message = findViewById([Link]);
btn = findViewById([Link]);
SmsManager smsManager = [Link]();
[Link](new [Link]() {
@Override
public void onClick(View v) {
String number = phn_no.getText().toString();
String msg = [Link]().toString();
Intent intent = new
Intent(getApplicationContext(),receive_sms.class);
PendingIntent pendingIntent =
[Link](getApplicationContext(),0,intent,PendingIntent.FLAG_UPDAT
E_CURRENT | PendingIntent.FLAG_IMMUTABLE);
[Link](number,null,msg,null,pendingIntent);
}
});
}
}