I am trying to send multiple data from database as an sms in the registered number. But I keep getting this as an error:
Sending SMS message: uid 10231 does not have android.permission.SEND_SMS
I already granted permission in my manifest to send sms.
Login Class
public void permission()
{
String[] permission={Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_SMS,
Manifest.permission.RECEIVE_SMS,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.SEND_SMS};
if(ContextCompat.checkSelfPermission(Login.this,
permission[0])== PackageManager.PERMISSION_GRANTED);
else
{
ActivityCompat.requestPermissions(Login.this,permission,1);
}
}
@Override
public void onResponse(Call<ResObj> call, Response<ResObj> response) {
ResObj resObj = response.body();
if(response.isSuccessful()) {
String phoneNum = et_mobile.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
String spamMessage = "Srno: " + resObj.getSrNo() +
"Date: " + resObj.getDate() +
"In: " + resObj.getTimeIn() +
"Out: " + resObj.getTimeOut() +
"JO#: " + resObj.getJoNo() +
"CoPer: " + resObj.getContactPerson() +
"BR: " + resObj.getDesignation() +
"CNum: " + resObj.getContactNo();
ArrayList<String> sms;
sms = smsManager.divideMessage(spamMessage);
smsManager.sendMultipartTextMessage(phoneNum, null,sms,null, null);
//smsManager.sendTextMessage(phoneNum, null, spamMessage, null, null);
Intent intent = new Intent(Login.this, ListActivity.class);
intent.putExtra("mobile", mobile);
startActivity(intent);
} else{
Toast.makeText(Login.this, "Phone Number is incorrect!", Toast.LENGTH_SHORT).show();
}
}
Android Manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>