Java.lang.securityexception: Sending Sms Message: Uid 10051 Does Not Have Android.permission.send_sms
guys i have problem with sms manager about sms scheduled...in manifest i used `` but i get this error...i do
Solution 1:
Copy and paste this code for sending sms services will done.
Button sendBtn = (Button)findViewById(R.id.senbtn);
sendBtn.setOnClickListener(newView.OnClickListener() {
publicvoidonClick(View view) {
sendSMSMessage();
}
});
}
protectedvoidsendSMSMessage() {
phoneNo = txtphoneNo.getText().toString();
message = txtMessage.getText().toString();
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {
} else {
ActivityCompat.requestPermissions(this,
newString[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);
}
}
}
@OverridepublicvoidonRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
switch (requestCode) {
caseMY_PERMISSIONS_REQUEST_SEND_SMS: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, message, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.", Toast.LENGTH_LONG).show();
return;
}
}
}
}
add this in menifest file:
<uses-permissionandroid:name="android.permission.SEND_SMS"/>
Solution 2:
Step 1your menifest permission is
<uses-permission android:name="android.permisson.SEND_SMS"/>
update it with
<uses-permissionandroid:name="android.permission.SEND_SMS"/>
its
android.permission.SEND_SMS
not android.permisson.SEND_SMS
permission spelling is wrong
step2
<receiverandroid:name=".AlarmReceiver"><intent-filter><actionandroid:name="android.provider.Telephony.SMS_RECEIVED" /></intent-filter></receiver>
Solution 3:
The big reason for not getting your permission nowadays is because your project has a targetSdkVersion of 23 or higher, and the permission that you are requesting is "dangerous". In Android 6.0 you can give manually permission:
const onPermissionHandle = async () => {
// We need to ask permission for Android onlyif (Platform.OS === 'android') {
// Calling the permission functionalert(granted);
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.SEND_SMS,
{
title: 'Example App SEND_SMS Permission',
message: 'Example App needs access to your SEND_SMS',
},
);
alert(granted);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// Permission Grantedalert('You can use the SEND_SMS');
} else {
// Permission Deniedalert('SEND_SMS Permission Denied');
}
} else {
alert('You can use the SEND_SMS ');
}
};
Solution 4:
you need to give runtime permission for OS marshmallow and above
go through this link
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//SEE NEXT STEP
}else{
sendSms();
}
if (checkSelfPermission(Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
//SEE NEXT STEP
} else {
sendSMS();
}
if (shouldShowRequestPermissionRationale(Manifest.permission.SEND_SMS)) {
//show some description about this permission to the user as a dialog, toast or in Snackbar
} else {
//request for the permission
}
@OverridepublicvoidonRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Snackbar.make(findViewById(R.id.rl), "Permission Granted",
Snackbar.LENGTH_LONG).show();
sendSMS();
} else {
Snackbar.make(findViewById(R.id.rl), "Permission denied",
Snackbar.LENGTH_LONG).show();
}
}
Solution 5:
After hours of debugging, I found out that adding this permission to the xml file does not produce the error anymore:
<uses-permission-sdk-23android:name="android.permission.READ_PHONE_STATE"/>
Post a Comment for "Java.lang.securityexception: Sending Sms Message: Uid 10051 Does Not Have Android.permission.send_sms"