81 Send SMS Android App in Android Studio Application (Short Message Service)

Опубликовано: 01 Январь 1970
на канале: tech fort
3,762
like

Send the SMS Android Application (Short Message Service)
How to Create a android application to send SMS (Short Message Service)
android.permission.SEND_SMS
android:name="android.permission.RECEIVE_SMS
uses-permission android:name="android.permission.READ_PHONE_STATE"


Button sendSMS;
EditText phoneNo;
EditText mess;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNo=(EditText)findViewById(R.id.phoneNo);
mess=(EditText)findViewById(R.id.message);
sendSMS=(Button)findViewById(R.id.sendSMS);

sendSMS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pno=phoneNo.getText().toString().trim();
String message=mess.getText().toString();

try {

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);


SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(pno, null, message, pi, null);

Toast.makeText(getApplicationContext(), "SMS Sent successfully..... ",
Toast.LENGTH_LONG).show();
}catch (Exception e){
Log.e("MainActivity Error ",e.getMessage());
Toast.makeText(getApplicationContext(), "Failed Error :"+e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
}


I will test this sms application in My Physical Andorid Device, BUT not in AVD.


Please Do enable permissions from your Physical Android Device/mobile.

Go to Settings --- Permissions --- SMS --- Select Your Application --- Enable Permissions.




boss.yhb.com.a70smssendingapp W/System.err:
java.lang.SecurityException: Sending SMS message:
uid 10152 does not have android.permission.SEND_SMS.

#android #app #SMS #Message